/* Myanmar Glyph Studio — lacquerware palette (paper / ink / lacquer red / gold) */
:root {
  --bg: #fbf7ef;
  --surface: #f3ecdd;
  --surface-2: #ede4d0;
  --ink: #26201a;
  --muted: #6e6154;
  --accent: #a8352f;
  --gold: #96701c;
  --line: #dfd4bf;
  --canvas-bg: #fffdf8;
  --good: #3e7048;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1713;
    --surface: #27201a;
    --surface-2: #302821;
    --ink: #ede3d2;
    --muted: #a79885;
    --accent: #e0705c;
    --gold: #d2a544;
    --line: #3c332a;
    --canvas-bg: #241d17;
    --good: #7fb389;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1713;
  --surface: #27201a;
  --surface-2: #302821;
  --ink: #ede3d2;
  --muted: #a79885;
  --accent: #e0705c;
  --gold: #d2a544;
  --line: #3c332a;
  --canvas-bg: #241d17;
  --good: #7fb389;
}

/* Bundled guide face: unmodified SIL Padauk 6.000 (OFL) — see fonts/README.md.
   Without it, system Myanmar fonts show empty boxes for stacked guides. */
@font-face {
  font-family: "Padauk";
  src: local("Padauk"), url("../fonts/Padauk-Regular.ttf") format("truetype");
  font-display: swap;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior: none;      /* no pull-to-refresh while drawing */
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  -webkit-tap-highlight-color: transparent;
}
.mm { font-family: "GlyphStudioGuide", Padauk, "Myanmar MN", "Noto Sans Myanmar", "Myanmar Text", sans-serif; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.85em; color: var(--muted); }

button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap;
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border-bottom: 2px solid var(--line);
  flex-shrink: 0;
}
.drawer-toggle { display: none; font-size: 1.1rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.brand-mark {
  font-size: 1.7rem; color: var(--accent); line-height: 1;
  background: var(--surface-2); border-radius: 8px; padding: 0.2rem 0.5rem;
}
.topbar h1 { font-size: 1rem; margin: 0; white-space: nowrap; }
.tagline { margin: 0; font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.meta-fields { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.meta-fields label { display: flex; flex-direction: column; font-size: 0.68rem; color: var(--muted); gap: 2px; }
.meta-fields input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.3rem 0.5rem; width: 10rem;
}
.project-actions { margin-left: auto; display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.secondary-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.menu-toggle { display: none; }

/* ---- bottom sheet (mobile project menu) ---- */
.sheet {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-card {
  background: var(--bg); border-top: 2px solid var(--line);
  border-radius: 16px 16px 0 0; width: 100%; max-width: 34rem;
  max-height: 82dvh; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  animation: sheet-up 0.2s ease;
}
@keyframes sheet-up { from { transform: translateY(18px); opacity: 0.6; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.7rem 1rem; border-bottom: 1px solid var(--line);
}
.sheet-head strong { font-size: 0.95rem; }
.sheet-body { padding: 0.9rem 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.9rem; }
.sheet-body .secondary-actions,
.sheet-body .meta-fields { display: flex !important; flex-wrap: wrap; gap: 0.5rem; }
.sheet-body .meta-fields { flex-direction: column; }
.sheet-body .meta-fields input { width: 100%; }
.sheet-body .btn { flex: 1 1 auto; justify-content: center; }

/* ---- thumb-reachable action bar (mobile) ---- */
.mobile-bar { display: none; }

/* ---- buttons ---- */
.btn {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 0.35rem 0.7rem; cursor: pointer; min-height: 34px;
}
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--accent); }
.btn.tool.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.icon-btn { min-width: 34px; padding: 0.35rem 0.5rem; }
/* larger touch targets on touch devices */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .icon-btn { min-width: 44px; }
  .chip { min-width: 2.9rem !important; height: 2.9rem !important; font-size: 1.25rem !important; }
}

/* ---- layout ---- */
.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 300px; flex-shrink: 0; overflow-y: auto;
  border-right: 2px solid var(--line); background: var(--surface);
  padding: 0.7rem;
  -webkit-overflow-scrolling: touch;
}
.progress-line {
  font-size: 0.78rem; font-weight: 600; color: var(--gold);
  padding-bottom: 0.5rem; border-bottom: 1px solid var(--line); margin-bottom: 0.4rem;
}
.sidebar details { margin-bottom: 0.3rem; }
.sidebar summary {
  cursor: pointer; display: flex; align-items: baseline; gap: 0.45rem;
  padding: 0.45rem 0.2rem; border-radius: 6px; list-style-position: inside;
}
.sidebar summary:hover { background: var(--surface-2); }
.grp-name { font-weight: 600; font-size: 0.82rem; }
.grp-my { color: var(--muted); font-size: 0.78rem; }
.grp-progress { margin-left: auto; font-size: 0.72rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 5px; padding: 0.3rem 0.1rem 0.5rem; }
.chip {
  min-width: 2.3rem; height: 2.3rem; font-size: 1.05rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; position: relative; padding: 0 0.3rem;
}
.chip:hover { border-color: var(--gold); }
.chip.drawn { background: var(--surface-2); border-color: var(--good); }
.chip.drawn::after {
  content: "●"; position: absolute; top: -2px; right: 1px;
  font-size: 0.55rem; color: var(--good);
}
.chip.active { border: 2px solid var(--accent); }
/* variant chips: the letter alone, with the form shown by a marker bar —
   a combining low line would be an empty box on many devices */
.chip[data-variant="sub"] { border-bottom: 3px solid var(--gold); }
.chip[data-variant="alt"]::before {
  content: "*"; position: absolute; top: 0; left: 3px;
  font-size: 0.6rem; color: var(--gold);
}
.sidebar-note {
  margin-top: 0.8rem; font-size: 0.72rem; color: var(--muted);
  background: var(--surface-2); border-radius: 8px; padding: 0.6rem 0.7rem;
}
.sidebar-note code { font-size: 0.95em; }
.drawer-overlay {
  display: none;
}

/* ---- workspace ---- */
.workspace {
  flex: 1; padding: 0.6rem 0.8rem; min-width: 0;
  display: flex; flex-direction: column; min-height: 0;
}
.glyph-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.4rem; flex-shrink: 0; }
.glyph-head .big { font-size: 2.2rem; line-height: 1.1; color: var(--accent); min-width: 3rem; text-align: center; }
.glyph-id { min-width: 0; overflow: hidden; }
.glyph-id > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { font-size: 0.8rem; color: var(--muted); }
.stepper { margin-left: auto; display: flex; gap: 0.3rem; }

.toolbar {
  display: flex; gap: 0.6rem 1.2rem; flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.4rem 0.7rem; margin-bottom: 0.5rem; flex-shrink: 0;
}
.tool-group { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.more-tools { display: none; }
.tool-sep { width: 1px; height: 22px; background: var(--line); margin: 0 0.3rem; }
.sliders label, .checks label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; color: var(--muted); }
.sliders input[type="range"] { width: 84px; accent-color: var(--accent); }
.checks .advance {
  width: 5rem; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 0.25rem 0.4rem;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
#zoomLabel { font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.extras label { display: flex; align-items: center; gap: 0.3rem; font-size: 0.75rem; color: var(--muted); }
.extras .advance {
  width: 5rem; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 0.25rem 0.4rem;
}
.sel {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.25rem 0.35rem; max-width: 7.5rem;
}

.canvas-wrap {
  flex: 1; min-height: 200px; position: relative;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--canvas-bg);
}
#glyphCanvas { display: block; cursor: crosshair; width: 100%; height: 100%; }
.canvas-tip {
  position: absolute; bottom: 6px; right: 10px; font-size: 0.68rem;
  color: var(--muted); pointer-events: none; opacity: 0.8;
}

.testdrive {
  display: flex; align-items: center; gap: 0.7rem; margin-top: 0.5rem;
  flex-wrap: wrap; flex-shrink: 0;
}
.testdrive label { font-size: 0.72rem; font-weight: 600; color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; }
.td-toggle { display: none; }
.preset-label { font-size: 0.72rem; color: var(--muted); }
.preset-row { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.preset { padding: 0.2rem 0.5rem; min-height: 28px; font-size: 0.85rem; }
.testdrive input {
  flex: 0 1 18rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 1rem; min-width: 8rem;
}
.preview {
  flex: 1 1 12rem; font-family: "GlyphStudioPreview", Padauk, "Myanmar MN", "Noto Sans Myanmar", sans-serif;
  font-size: 1.9rem; line-height: 1.45; min-height: 2rem; padding: 0.1rem 0.4rem;
  white-space: nowrap; overflow-x: auto;
}
.preview.empty { color: var(--muted); }

/* ---- focus mode: nothing but the canvas ---- */
body.focus .topbar,
body.focus .sidebar,
body.focus .toolbar,
body.focus .testdrive { display: none; }
body.focus .workspace { padding: 0.4rem; }
body.focus .glyph-head { margin: 0 0 0.3rem; }

/* ---- help modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  max-width: 34rem; width: 100%; max-height: 85dvh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.1rem; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 0.9rem 1.1rem; overflow-y: auto; font-size: 0.88rem; line-height: 1.55; }
.modal-body h3 { font-size: 0.85rem; margin: 1rem 0 0.3rem; color: var(--gold); }
.modal-body ul { margin: 0.2rem 0 0.6rem; padding-left: 1.2rem; }
.modal-body li { margin-bottom: 0.25rem; }
.modal-body pre {
  background: var(--surface-2); border-radius: 8px; padding: 0.6rem 0.8rem;
  overflow-x: auto; font-size: 0.78rem;
}
.modal-body a { color: var(--accent); }

.install-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(0.8rem + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 0.5rem 0.7rem; z-index: 58;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  max-width: min(94vw, 30rem); font-size: 0.85rem;
}
@media (max-width: 640px) { .install-bar { bottom: calc(4.2rem + env(safe-area-inset-bottom)); } }

#toast {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 0.6rem 1.1rem; border-radius: 9px;
  font-size: 0.85rem; opacity: 0; pointer-events: none; transition: all 0.25s;
  max-width: 90vw; z-index: 60;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- tablets and phones: sidebar becomes a slide-in drawer ---- */
@media (max-width: 1000px) {
  .drawer-toggle { display: inline-block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    width: min(320px, 85vw);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    padding-top: calc(0.7rem + env(safe-area-inset-top));
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-overlay {
    display: block; position: fixed; inset: 0; z-index: 39;
    background: rgba(0, 0, 0, 0.35);
  }
  .drawer-overlay[hidden] { display: none; }
  .meta-fields { display: none; }
  .tagline { display: none; }
  .brand-text h1 { font-size: 0.92rem; }
}

@media (max-width: 640px) {
  /* collapse fine-tuning controls behind the ⚙ button to save canvas space */
  .more-tools { display: inline-block; }
  .more-tools.active { background: var(--accent); color: #fff; border-color: var(--accent); }
  .toolbar .sliders, .toolbar .checks, .toolbar .extras { display: none; width: 100%; }
  .toolbar.expanded .sliders, .toolbar.expanded .checks, .toolbar.expanded .extras { display: flex; }

  /* one compact header row: menu · brand · ⋯ · Export */
  .topbar { gap: 0.4rem; padding: 0.3rem 0.5rem; flex-wrap: nowrap; }
  .brand-mark { font-size: 1.25rem; padding: 0.15rem 0.4rem; }
  .brand-text { min-width: 0; overflow: hidden; }
  .brand-text h1 { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; }
  /* ⚙ stays put while the tools scroll past it */
  .toolbar > .more-tools { flex: 0 0 auto; }
  .secondary-actions { display: none; }
  .menu-toggle { display: inline-block; }
  .project-actions { gap: 0.3rem; flex-wrap: nowrap; }
  .project-actions .primary { padding: 0.35rem 0.6rem; white-space: nowrap; }

  .workspace { padding: 0.35rem 0.5rem 0; }
  .glyph-head { gap: 0.5rem; margin-bottom: 0.3rem; }
  .glyph-head .big { font-size: 1.7rem; min-width: 2.2rem; }
  .hint, .canvas-tip { display: none; }
  /* prev/next/focus live in the bottom bar on phones */
  .stepper #btnPrev, .stepper #btnNext, .stepper #btnNextUndrawn { display: none; }

  /* tools stay on ONE row that scrolls sideways — the canvas keeps the space */
  .toolbar { padding: 0.3rem 0.4rem; gap: 0.4rem; }
  .toolbar .tool-group:first-child {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 0; min-width: 0;   /* shares the row with ⚙, scrolls inside */
  }
  .toolbar .tool-group:first-child::-webkit-scrollbar { display: none; }
  .toolbar .tool-group:first-child .btn { flex: 0 0 auto; }
  .tool span { display: none; }            /* icon-only tool buttons */
  .sliders input[type="range"] { width: 100%; min-width: 120px; }
  .toolbar.expanded .sliders label,
  .toolbar.expanded .extras label { flex: 1 1 46%; }

  .canvas-wrap { min-height: 42dvh; }
  .preview { font-size: 1.5rem; }

  /* test drive folds away — tap the label to bring it back */
  .testdrive { margin-top: 0.35rem; gap: 0.4rem; }
  .td-toggle {
    display: inline-flex; background: none; border: 0; color: var(--gold);
    font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; padding: 0.25rem 0; cursor: pointer;
  }
  .testdrive.collapsed > *:not(.td-toggle) { display: none; }
  .testdrive > label { display: none; }

  /* thumb zone */
  .mobile-bar {
    display: flex; gap: 0.3rem; align-items: center; justify-content: space-between;
    background: var(--surface); border-top: 2px solid var(--line);
    padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom));
    flex-shrink: 0;
  }
  .mobile-bar .btn { flex: 1 1 0; min-height: 46px; font-size: 1.05rem; }
  .mobile-bar .btn.wide { flex: 1.6 1 0; font-size: 0.8rem; }
  body.focus .mobile-bar { display: flex; }
}

/* very narrow phones: the mark alone identifies the app */
@media (max-width: 359px) {
  .brand-text h1 { display: none; }
}

/* phones in landscape: every pixel of height counts */
@media (max-width: 900px) and (max-height: 460px) {
  .testdrive, .glyph-head .glyph-id { display: none; }
  .canvas-wrap { min-height: 30dvh; }
}

/* a device with a stylus gets the precise controls back */
@media (max-width: 640px) and (pointer: fine) {
  .tool span { display: inline; }
}
