:root {
  --c-base: #ffffff;
  --c-main: #000000;
  --c-ui: #4d4d4d;
  --c-main-soft: rgba(0, 0, 0, 0.05);
  --c-main-muted: rgba(0, 0, 0, 0.62);
  --c-main-border: rgba(0, 0, 0, 0.14);
  --code-tag: #8a2be2;
  --code-attr: #005cc5;
  --code-value: #b31d28;
  --code-text: #24292e;
  --code-comment: #6a737d;
  --font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  --radius: 8px;
  --line: 1.65;
}

* {
  box-sizing: border-box;
}

html {
  color: var(--c-ui);
  background: var(--c-base);
  font-family: var(--font-body);
  line-height: var(--line);
  font-weight: 400;
}

body {
  min-width: 320px;
  margin: 0;
}

button,
textarea,
input {
  font: inherit;
}

button {
  color: inherit;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 10;
  transform: translateY(-150%);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--c-main);
  background: var(--c-base);
  color: var(--c-main);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--c-base);
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  max-width: none;
  min-height: 68px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 3vw, 2rem);
}

.brand,
.nav-links,
.panel-header,
.html-actions,
.segmented {
  display: flex;
  align-items: center;
}

.brand {
  gap: var(--space-2);
  font-size: 1.1rem;
  font-weight: 500;
}

.nav-links {
  flex: 1;
  flex-wrap: wrap;
  gap: var(--space-1);
  justify-content: flex-start;
  margin-left: var(--space-3);
}

.nav-links a {
  color: var(--c-ui);
  font-size: 0.95rem;
  font-weight: 400;
  text-decoration: none;
}

.nav-links span {
  color: var(--c-main-muted);
}

.app-shell {
  max-width: none;
  margin: 0 auto;
  padding: var(--space-2) clamp(1rem, 2vw, 1.5rem) var(--space-5);
}

h2 {
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: 0;
  margin: 0;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: 0;
}

.input-panel {
  background: var(--c-main-soft);
  min-height: auto;
  padding: var(--space-2);
}

.preview-panel {
  min-height: auto;
}

.panel-header {
  justify-content: flex-start;
  gap: var(--space-3);
}

.html-actions {
  width: 100%;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: space-between;
}

.output-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
}

.markdown-body {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(160px, 220px);
  gap: var(--space-2);
  align-items: stretch;
}

.upload-area {
  display: grid;
  gap: var(--space-2);
}

.button,
.segment {
  min-height: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--c-ui);
  cursor: pointer;
  font-weight: 500;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-3);
  text-decoration: none;
  white-space: nowrap;
}

.output-actions > .button,
.download-menu > .button {
  border: 1px solid var(--c-main);
  background: var(--c-base);
  color: var(--c-main);
}

.download-menu {
  position: relative;
}

.download-options {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10;
  display: none;
  min-width: 100%;
  background: var(--c-base);
  padding-top: 2px;
}

.download-options button {
  display: block;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--c-main);
  border-top: 0;
  background: var(--c-base);
  color: var(--c-main);
  cursor: pointer;
  font: inherit;
  text-align: left;
  padding: 0 var(--space-3);
}

.download-menu:hover .download-options,
.download-menu:focus-within .download-options {
  display: block;
}

.drop-zone {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid var(--c-main);
  background: var(--c-base);
  color: var(--c-main);
  text-align: center;
  cursor: pointer;
}

.drop-zone.is-dragover {
  background: rgba(0, 0, 0, 0.1);
}

.drop-title {
  display: block;
  font-weight: 500;
}

#markdownInput {
  width: 100%;
  height: 70px;
  min-height: 70px;
  resize: vertical;
  border: 0;
  background: var(--c-base);
  color: var(--c-ui);
  font-family: var(--font-mono);
  font-size: 0.94rem;
  line-height: 1.7;
  padding: var(--space-2);
}

#previewFrame {
  width: 100%;
  display: block;
  height: auto;
  min-height: 0;
  border: 0;
  background: #ffffff;
  overflow: hidden;
}

.segmented {
  display: inline-flex;
  min-height: 44px;
  align-items: flex-end;
  gap: var(--space-2);
  background: transparent;
}

.segment {
  min-width: 70px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--c-ui);
  padding: 0 var(--space-3);
}

.segment.is-active {
  background: transparent;
  color: var(--c-main);
  box-shadow: inset 0 -2px 0 var(--c-main);
}

.html-viewer {
  width: min(100%, 1200px);
  flex: 1;
  min-height: 0;
  overflow: visible;
  margin: 0 auto;
  background: #fafafa;
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.72;
  padding: var(--space-3);
  white-space: pre-wrap;
  word-break: break-word;
}

.html-viewer .code-tag {
  color: var(--code-tag);
  font-weight: 700;
}

.html-viewer .code-attr {
  color: var(--code-attr);
}

.html-viewer .code-value {
  color: var(--code-value);
}

.html-viewer .code-comment {
  color: var(--code-comment);
}

.color-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
  margin: 0 0.12rem;
  white-space: nowrap;
}

.color-chip::before {
  content: "";
  width: 0.9em;
  height: 0.9em;
  border: 1px solid rgba(0, 0, 0, 0.24);
  background: var(--chip-color);
}

.is-hidden {
  display: none;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 3px solid var(--c-main);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  .html-viewer {
    min-height: 560px;
  }

  .markdown-body {
    grid-template-columns: 1fr;
  }

  #markdownInput {
    grid-column: auto;
  }
}

@media (max-width: 560px) {
  .nav {
    align-items: flex-start;
    flex-direction: column;
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
  }

  .nav-links,
  .panel-header {
    width: 100%;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .html-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .html-actions .segmented {
    grid-column: 1 / -1;
  }

  .output-actions {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .output-actions #openButton {
    grid-column: 1 / -1;
  }

  .panel-header {
    align-items: stretch;
    flex-direction: column;
    gap: var(--space-2);
  }

  .button {
    width: 100%;
  }

  .drop-zone {
    align-items: center;
    flex-direction: column;
    gap: 0.15rem;
    min-height: 56px;
  }

  .segmented {
    width: 100%;
  }

  .segment {
    flex: 1;
  }

  .panel {
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
