/* TopoGlyph — a light, self-authored "paper" aesthetic instead of pulling in
 * a full CSS framework (papercss/paper.css are either a whole component
 * system or tuned for print-preview layout, not a single output-display
 * widget — see topoglyph-website's design notes). Core ideas borrowed from
 * those projects: a monospace-first "receipt paper" panel with a soft
 * shadow and a torn/perforated edge, kept intentionally simple.
 */

:root {
  --paper-bg: #fdfbf7;
  --paper-edge: #e8e3d8;
  --ink: #1b1b18;
  --ink-muted: #6b6b63;
  --accent: #b0413e;
  --shadow: 0 2px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.08);
  --page-bg: #ece7dc;
  --page-bg-gradient: radial-gradient(circle at 50% 0%, #f4f0e6 0%, #ece7dc 60%);
  --input-bg: #fff;
  --border-color: var(--border-color);
  --stripe-bg: rgba(0, 0, 0, 0.015);
  --code-bg: var(--code-bg);
  --dropzone-bg: var(--dropzone-bg);
  --mono:
    "Cascadia Code", "JetBrains Mono", "IBM Plex Mono", ui-monospace, "Apple Braille", monospace;
  --serif: "IBM Plex Serif", Georgia, serif;
}

:root[data-theme="dark"] {
  --paper-bg: #1e1e1e;
  --paper-edge: #333333;
  --ink: #e8e8e8;
  --ink-muted: #999999;
  --accent: #e57373;
  --shadow: 0 2px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.5);
  --page-bg: #121212;
  --page-bg-gradient: radial-gradient(circle at 50% 0%, #1a1a1a 0%, #121212 60%);
  --input-bg: #2d2d2d;
  --border-color: rgba(255, 255, 255, 0.25);
  --stripe-bg: rgba(255, 255, 255, 0.03);
  --code-bg: rgba(255, 255, 255, 0.1);
  --dropzone-bg: rgba(229, 115, 115, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--page-bg);
  background-image: var(--page-bg-gradient);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.5;
}

/* ---- App Layout ---- */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--paper-bg);
  border-bottom: 1px solid var(--paper-edge);
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.header-brand h1 {
  font-family: var(--mono);
  font-size: 20px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0;
}

.header-brand p.tagline {
  color: var(--ink-muted);
  font-size: 13px;
  margin: 0;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-icon {
  color: var(--ink);
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.header-icon:hover {
  opacity: 1;
}

.app-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--paper-bg);
  border-right: 1px solid var(--paper-edge);
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.sidebar-content {
  flex: 1;
}

.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
  position: relative;
  overflow: hidden;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px dashed var(--paper-edge);
}

.editor-header h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.editor-actions {
  position: absolute;
  bottom: 24px;
  right: 24px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.editor-content {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.editor-content pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1;
  color: var(--ink);
  white-space: pre;
  transition: font-size 0.1s ease;
}

.editor-content pre.empty-state {
  color: var(--ink-muted);
  font-family: var(--serif);
  font-size: 14px;
  padding: 60px 20px;
  text-align: center;
  white-space: normal;
}

.output-meta {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  border-radius: 2px;
}

.editor-content .output-meta,
.editor-header .output-meta {
  position: absolute;
  bottom: 24px;
  left: 24px;
  background: var(--page-bg);
  padding: 4px 8px;
  pointer-events: none;
  z-index: 5;
}






nav.lang-switch a,
nav.lang-switch span {
  padding: 3px 8px;
  border: 1px solid var(--paper-border, var(--border-color));
  border-radius: 2px;
  text-decoration: none;
  color: var(--ink);
}

nav.lang-switch a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

nav.lang-switch span[aria-current="page"] {
  background: var(--ink);
  color: var(--paper-bg);
  border-color: var(--ink);
}


/* ---- Paper panel: the reusable "sheet" container ---- */
.paper {
  position: relative;
  background: var(--paper-bg);
  box-shadow: var(--shadow);
  border-radius: 2px;
  padding: 28px 28px 24px;
  margin-bottom: 28px;
}

/* Perforated top/bottom edge, evoking continuous printer paper. Rendered as
 * a repeating radial-gradient "row of holes" rather than an image asset, so
 * it scales with any panel width and needs no extra request. */
.paper::before,
.paper::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 10px;
  background-image: radial-gradient(
    circle,
    var(--paper-edge) 3px,
    transparent 3.5px
  );
  background-size: 20px 10px;
  background-repeat: repeat-x;
  background-position: 6px center;
}

.paper::before {
  top: -5px;
}

.paper::after {
  bottom: -5px;
}

.paper h2 {
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 16px;
  border-bottom: 1px dashed var(--paper-edge);
  padding-bottom: 10px;
}

/* ---- The text-art output itself: real, selectable <pre> text ---- */






/* ---- Controls ---- */
.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  /* Slider labels ("RELAXATION ROUNDS 3") wrap onto a second line more
   * often than short ones ("ROWS") in the same auto-fit grid row; a fixed
   * min-height keeps every row's inputs starting at the same y-position
   * instead of the shorter labels' rows looking misaligned next to the
   * longer, wrapped ones. Stays a block (not flex) so the label text and
   * its value span keep the natural inline-with-wrapping layout the
   * template's whitespace already produces.
   */
  display: block;
  min-height: 2.6em;
}

.field input[type="text"],
.field input[type="number"],
.field select {
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--paper-edge);
  border-radius: 2px;
  background: var(--input-bg);
  color: var(--ink);
}

.field-hint {
  font-family: var(--serif);
  font-size: 12px;
  color: var(--ink-muted);
  margin: 6px 0 0;
  line-height: 1.5;
}

.field-hint code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--code-bg);
  padding: 1px 4px;
  border-radius: 2px;
}

/* ---- Usage panel (collapsible "How to use" help) ---- */
.usage-panel {
  padding: 0 28px;
}

.usage-panel summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  padding: 16px 0;
  list-style: none;
}

.usage-panel summary::-webkit-details-marker {
  display: none;
}

.usage-panel summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s ease;
}

.usage-panel details[open] summary::before {
  transform: rotate(90deg);
}

.usage-body {
  padding-bottom: 20px;
  font-size: 14px;
  line-height: 1.6;
}

.usage-body h3 {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 20px 0 8px;
}

.usage-body h3:first-child {
  margin-top: 0;
}

.usage-body ol,
.usage-body p {
  margin: 0 0 8px;
  padding-left: 22px;
}

.usage-body p {
  padding-left: 0;
}

.usage-body li {
  margin-bottom: 6px;
}

.usage-body code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 1px 4px;
  border-radius: 2px;
}

.field input[type="range"] {
  width: 100%;
}

.field .range-value {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
}

.field-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field-checkbox label {
  text-transform: none;
  font-size: 13px;
  color: var(--ink);
}

.dropzone {
  border: 2px dashed var(--paper-edge);
  border-radius: 4px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--dropzone-bg);
}

.dropzone p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 14px;
}

.dropzone .filename {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  margin-top: 8px;
}

.btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 10px 20px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--ink);
  color: var(--paper-bg);
  cursor: pointer;
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease;
}

.btn:hover:not(:disabled) {
  box-shadow: 0 2px 0 var(--ink);
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.is-secondary {
  background: transparent;
  color: var(--ink);
}

.actions-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.status-line {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 12px;
  min-height: 1.4em;
}

.status-line.is-error {
  color: var(--accent);
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 16px;
  border: 1px solid var(--paper-edge);
  border-radius: 2px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
}

.tab-btn.is-active {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--code-bg);
}

.tab-panel.is-hidden {
  display: none;
}

/* ---- Progress bar (video conversion) ---- */
.progress-track {
  height: 6px;
  border-radius: 3px;
  background: var(--paper-edge);
  margin-top: 12px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}

/* ---- Glyph atlas preview grid ---- */
.glyph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 20px;
}

.glyph-card {
  border: 1px solid var(--paper-edge);
  border-radius: 3px;
  padding: 12px;
  text-align: center;
  background: var(--input-bg);
}

.glyph-card .glyph-token {
  font-family: var(--mono);
  font-size: 22px;
  margin-bottom: 6px;
  min-height: 1.4em;
}

.glyph-card .glyph-mask {
  display: block;
  margin: 0 auto 8px;
  border: 1px solid var(--paper-edge);
}

.glyph-card .glyph-meta {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--ink-muted);
  text-align: left;
  line-height: 1.5;
}

footer.site-footer {
  text-align: center;
  color: var(--ink-muted);
  font-size: 12px;
  margin-top: 40px;
}

footer.site-footer a {
  color: var(--ink-muted);
}

a {
  color: var(--accent);
}

@media (max-width: 600px) {
  .container {
    padding: 32px 14px 60px;
  }
  header.masthead h1 {
    font-size: 20px;
  }
  .output-scroll pre {
    font-size: 8px;
  }
  /* Action buttons (Render/Copy/Download, Convert/Download .tglyph) wrap to
   * their own full-width row below this breakpoint instead of shrinking or
   * spilling past the paper panel's padding, since a stacked layout reads
   * better than several half-width buttons once labels like
   * "Download .tglyph" no longer fit on one line next to their siblings. */
  .actions-row {
    flex-direction: column;
  }
  .actions-row .btn {
    width: 100%;
  }
  .tabs {
    flex-direction: column;
  }
  .tab-btn {
    width: 100%;
  }
}

/* ── Help dialog ────────────────────────────────────────────────── */
.help-dialog {
  border: none;
  border-radius: 8px;
  padding: 0;
  max-width: min(680px, 92vw);
  max-height: 80vh;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  background: var(--paper-bg);
  color: var(--text);
}
.help-dialog::backdrop { background: rgba(0,0,0,.45); }
.help-dialog-inner {
  padding: 28px 32px 28px;
  overflow-y: auto;
  max-height: 80vh;
  position: relative;
}
.help-dialog-close {
  position: absolute;
  top: 14px; right: 16px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.help-dialog-close:hover { color: var(--text); }
