/* Handwriting Font Maker — "retro OS + stationery" look.
   Colors and sizes follow docs/design/DESIGN.md. */

:root {
  --paper: #faf8f5;        /* window backgrounds */
  --paper-white: #ffffff;  /* inputs, canvas */
  --paper-dim: #f2eee9;    /* recessed areas, hover */
  --desk: #efeeeb;         /* page background behind windows */
  --ink: #1a1a1a;          /* borders, text */
  --ink-muted: #5f5a58;    /* secondary text (darker than DESIGN.md for contrast) */
  --rule: #d8d4cf;         /* faint lines */
  --rose: #d8989f;         /* primary accent */
  --rose-soft: #e8b4b8;    /* hover / tints */
  --rose-wash: #fbe9ea;    /* warning background */
  --periwinkle: #9caecf;
  --periwinkle-soft: #dde5f4;

  --font-mono: "Space Mono", ui-monospace, monospace;
  --font-display: "Space Grotesk", system-ui, sans-serif;

  --shadow-1: 2px 2px 0 var(--ink);
  --shadow-2: 3px 3px 0 var(--ink);
  --touch: 44px;           /* minimum touch target */
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, p, ol { margin: 0; }

button, input, textarea { font: inherit; color: inherit; }

/* Material Symbols icon font: write the icon name as the element's text. */
.icon {
  font-family: "Material Symbols Outlined";
  font-size: 20px;
  line-height: 1;
  font-weight: normal;
  font-style: normal;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar, title, status bar ---------- */

.system-bar,
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1rem;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.system-bar {
  background: var(--paper);
  border-bottom: 1px solid var(--ink);
  font-weight: 700;
}

.system-logo { display: flex; align-items: center; gap: 0.5rem; }
.logo-box { width: 14px; height: 14px; background: var(--rose); border: 1px solid var(--ink); }

.system-progress {
  border: 1px solid var(--ink);
  padding: 0.15rem 0.5rem;
  font-weight: 400;
  background: var(--paper-white);
}

.status-bar {
  background: var(--ink);
  color: var(--paper);
  margin-top: 1.5rem;
}

.page-head {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}

.title-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.tagline { color: var(--ink-muted); margin: 0.25rem 0 0.75rem; }

.button-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  border: 1px solid var(--ink);
  padding: 0 0.4rem;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--paper-white);
  white-space: nowrap;
}
.badge-blue { background: var(--periwinkle-soft); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0 0.9rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  box-shadow: var(--shadow-1);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.btn:hover:not(:disabled) { background: var(--paper-dim); }
/* "Mechanical" press: the button moves into its own shadow. */
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible,
.tab:focus-visible,
.glyph-cell:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--periwinkle);
  outline-offset: 2px;
}

.btn-primary { background: var(--rose); }
.btn-primary:hover:not(:disabled) { background: var(--rose-soft); }

.btn-danger { color: #8f2f2f; }

.btn-icon { width: var(--touch); padding: 0; }

.btn[aria-pressed="true"] { background: var(--rose); }
.btn-toggle[aria-pressed="true"] { background: var(--periwinkle-soft); }

/* Flat text-only button (prev / next above the canvas). */
.btn-ghost { box-shadow: none; border-color: transparent; background: transparent; font-weight: 400; }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink); }

.btn-wide { width: 100%; }

/* ---------- Desk layout ---------- */

.desk {
  display: grid;
  gap: 1.5rem;
  padding: 1.5rem 1rem 0;
  max-width: 1600px;
  margin: 0 auto;
  /* Phone / iPad portrait: one column, canvas first. */
  grid-template-columns: 1fr;
  grid-template-areas:
    "canvas"
    "glyphs"
    "side"
    "help";
}

.area-glyphs { grid-area: glyphs; }
.area-canvas { grid-area: canvas; }
.area-side   { grid-area: side; display: grid; gap: 1.5rem; align-content: start; }
.area-help   { grid-area: help; }

/* iPad portrait and up: glyphs next to preview/export under the canvas. */
@media (min-width: 760px) {
  .desk {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "canvas canvas"
      "glyphs side"
      "help   help";
  }
}

/* iPad landscape / desktop: three columns. */
@media (min-width: 1100px) {
  .desk {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) minmax(260px, 330px);
    grid-template-areas:
      "glyphs canvas side"
      "help   help   help";
    align-items: start;
  }
  /* Grid scrolls on its own so the page stays short. */
  .area-glyphs .glyph-grid { max-height: 62vh; overflow-y: auto; }
}

/* ---------- Window component ---------- */

.window {
  background: var(--paper);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow-2);
  min-width: 0;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 34px;
  padding: 0 0.5rem;
  border-bottom: 1px solid var(--ink);
  /* Pinstripes like old Mac title bars. */
  background: repeating-linear-gradient(to bottom, var(--paper) 0 2px, var(--rule) 2px 4px);
}

/* Little close box drawn with CSS. */
.wctl {
  width: 14px;
  height: 14px;
  border: 1px solid var(--ink);
  background: var(--paper);
  flex: none;
}

.wtitle {
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 0 0.6rem;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.wmeta { margin-left: auto; font-size: 11px; letter-spacing: 0.05em; background: var(--paper); padding: 0 0.3rem; white-space: nowrap; }

.wbody { padding: 0.9rem; }
.stack { display: grid; gap: 0.9rem; }

/* ---------- Glyph grid ---------- */

.progress-block { margin-bottom: 0.9rem; }
.progress-label { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 12px; margin-bottom: 0.3rem; }
.progress-bar { height: 14px; border: 1px solid var(--ink); background: var(--paper-white); }
.progress-fill { height: 100%; width: 0; background: var(--rose); border-right: 1px solid var(--ink); transition: width 0.2s; }
.progress-fill[style*="width: 0"] { border-right: 0; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.tab {
  min-height: var(--touch);
  padding: 0 0.65rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper-white);
  font-size: 12px;
  cursor: pointer;
}
.tab[aria-pressed="true"] { background: var(--rose); font-weight: 700; }

.grid-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.9rem 0 0.5rem;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.grid-section-title:first-child { margin-top: 0; }
/* Dotted "stitch" line after the section title. */
.grid-section-title::after {
  content: "";
  flex: 1;
  height: 2px;
  background-image: radial-gradient(var(--ink-muted) 1px, transparent 1px);
  background-size: 6px 2px;
}

.grid-cells {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 0.4rem;
}

.glyph-cell {
  position: relative;
  aspect-ratio: 1;
  min-height: var(--touch);
  border: 1px dashed var(--ink-muted);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0;
}
.glyph-cell .cell-char {
  font-family: sans-serif;  /* same default font as the canvas ghost */
  font-size: 24px;
  opacity: 0.35;
}
.glyph-cell .cell-mark {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 11px;
  font-weight: 700;
}

/* Thumbnail of the drawing; covers the whole cell, hidden until drawn. */
.glyph-cell .cell-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}
/* Small character name in the top-left corner, shown on drawn cells. */
.glyph-cell .cell-label {
  position: absolute;
  top: 1px;
  left: 4px;
  font-size: 10px;
  display: none;
}
.glyph-cell.is-done .cell-char { display: none; }
.glyph-cell.is-done .cell-thumb,
.glyph-cell.is-done .cell-label { display: block; }

.glyph-cell.is-done {
  border-style: solid;
  border-color: var(--ink);
  background: var(--paper-white);
  box-shadow: var(--shadow-1);
  color: var(--ink);
}
.glyph-cell.is-done .cell-char { opacity: 1; }

.glyph-cell.is-selected {
  border: 2px solid var(--ink);
  background: var(--rose);
  color: var(--ink);
}
.glyph-cell.is-selected .cell-char { opacity: 0.8; }

/* ---------- Canvas window ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.toolbar-group { display: flex; gap: 0.4rem; }
.segmented { display: flex; }
.segmented .btn { box-shadow: none; }
.segmented .btn + .btn { border-left: 0; }

.dot { display: block; border-radius: 50%; background: var(--ink); }
.dot-s { width: 5px; height: 5px; }
.dot-m { width: 10px; height: 10px; }
.dot-l { width: 16px; height: 16px; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0 0.7rem;
  border: 1px solid var(--ink);
  background: var(--paper-white);
  font-size: 13px;
  cursor: pointer;
}
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--rose); }

.canvas-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0.75rem 0 0.5rem;
  font-size: 13px;
}

.canvas-frame {
  border: 1px solid var(--ink);
  background: var(--paper-white);
  /* Faint paper grid behind the canvas. */
  background-image:
    linear-gradient(var(--paper-dim) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-dim) 1px, transparent 1px);
  background-size: 24px 24px;
  max-width: 640px;
  margin: 0 auto;
}

#draw-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  /* iPad: never scroll or zoom the page while drawing. */
  touch-action: none;
  cursor: crosshair;
}

.canvas-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  margin-top: 0.9rem;
}
.bearings { display: flex; flex-wrap: wrap; gap: 1rem; flex: 1; }
.btn-next { margin-left: auto; min-height: 52px; padding: 0 1.3rem; font-size: 14px; }

.slider { display: grid; gap: 0.2rem; font-size: 12px; min-width: 150px; flex: 1; }
.slider output { font-weight: 700; }
.slider input { width: 100%; min-height: var(--touch); accent-color: var(--rose); margin: 0; }

/* ---------- Preview + export ---------- */

.field { display: grid; gap: 0.3rem; }
.field-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }

input[type="text"],
textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper-white);
}

/* Ruled notebook paper for the preview text. */
textarea.paper {
  margin-top: 0.3rem;
  font-size: 30px;
  line-height: 44px;
  resize: vertical;
  background-image: linear-gradient(transparent 43px, var(--rule) 43px);
  background-size: 100% 44px;
  background-attachment: local;
}

.hint { font-size: 12px; color: var(--ink-muted); margin-top: 0.4rem; }

.warning {
  border: 1px solid var(--ink);
  background: var(--rose-wash);
  padding: 0.6rem 0.75rem;
  font-size: 12px;
}

/* ---------- Help ---------- */

.help-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.note {
  border: 1px solid var(--ink);
  box-shadow: var(--shadow-1);
  background: var(--paper-white);
  padding: 0.9rem;
  display: grid;
  gap: 0.5rem;
  align-content: start;
}
.note h3 {
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 0.4rem;
}
.note ol { padding-left: 1.2rem; display: grid; gap: 0.4rem; }

/* ---------- Dialog ---------- */

.dialog {
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  box-shadow: 4px 4px 0 var(--ink);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(26, 26, 26, 0.35); }
.dialog .wbody { display: grid; gap: 1rem; }
#dialog-message { white-space: pre-line; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 0.75rem; flex-wrap: wrap; }
.btn-danger-fill { background: #e9a3a3; }
.btn-danger-fill:hover:not(:disabled) { background: #f0bdbd; }
