/* ---------------------------------------------------------------------
   TODO Tool Name — style.css
   Starting point for a new Tools-Portal app. Everything up to the
   "-------- your content starts here --------" marker is the portal-wide
   contract (masthead + dark theme + page width) and should not be
   restructured — see README.md in this folder for what may/may not change.
   Below that marker, replace the placeholder example rules with your own.
   ------------------------------------------------------------------- */

:root {
  --paper: #f5f1e8;
  --paper-raised: #fffdf7;
  --ink: #1c1a15;
  --ink-soft: #5a5646;
  --ink-faint: #8a8570;
  --rule: #d8d0bc;
  --rule-strong: #b9ae8c;
  --accent: #b5482f;
  --accent-soft: #f0ded7;
  --focus: #1c1a15;
  --radius-sm: 3px;
  --radius-md: 6px;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;
}

/* ---------- Dark theme ----------
   Toggled via [data-theme="dark"] on <html> (set by the anti-FOUC inline
   script in index.html). Same token names as the light palette above are
   redefined here — every rule you write should read var(--paper)/
   var(--ink)/etc. so the whole page repaints on toggle without touching
   component styles. If you introduce your own extra color tokens (a
   category accent, a status color, ...), add BOTH a light value in :root
   above and a dark-safe value in this block — never leave one variant
   undefined (Kai.md: "Kategorie-/Akzentfarben... für Dark Mode ebenfalls
   beide Varianten pflegen"). */
html[data-theme="dark"] {
  --paper: #1b1914;
  --paper-raised: #262319;
  --ink: #ece6d6;
  --ink-soft: #b7ae95;
  --ink-faint: #8f8870;
  --rule: #3a362a;
  --rule-strong: #55503e;
  --accent: #e2825f;
  --accent-soft: #3a2620;
  --focus: #ece6d6;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-serif);
  line-height: 1.5;
  min-height: 100vh;
}

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

/* Complex-script rendering (Kai.md): if this tool shows Thai or another
   non-Latin/diacritic-heavy script, give it its own generous line-height
   and visible overflow so stacked marks are never clipped. Uncomment and
   adapt — do not just reuse body's line-height: 1.5, it is too tight for
   Thai vowel/tone-mark stacks.
[lang="th"] {
  font-family: var(--font-thai), var(--font-serif);
  line-height: 1.8;
}
*/

/* ================= MASTHEAD ==================================
   Standardized 2-line header. Same class names/structure across the
   portal, web-countdown, and every tool app — DO NOT rename, DO NOT
   restructure. Copy this block verbatim into a new tool; only the
   *values* (accent color references, max-widths) may be adapted to a
   tool's own palette if it has one (see thai-flashcards/style.css for an
   example of a tool with its own jade/saffron palette reusing this exact
   block with different var() targets). */

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

.masthead {
  padding-bottom: 1.15rem;
}

.masthead-rule {
  border: none;
  border-top: 2px solid var(--ink);
  margin: 0 0 2.5rem;
}

.masthead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.masthead-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.home-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  border-radius: 50%;
  color: var(--ink-soft);
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.home-icon:hover {
  background: var(--accent-soft);
  color: var(--ink);
}

.home-icon:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .home-icon {
    transition: none;
  }
}

.brand-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: var(--paper);
  font-size: 1.05rem;
}

.brand-tile img {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  /* External <img> SVGs do not inherit currentColor. Brand-tile is ink-on-paper
     inverted (dark tile / paper glyph). Force monochrome paint to match. */
  filter: brightness(0) invert(1);
}
html[data-theme="dark"] .brand-tile img {
  /* Dark theme: --ink tile is light; keep icon dark. */
  filter: brightness(0);
}


.brand-title {
  font-size: clamp(1.3rem, 3.2vw, 1.6rem);
  margin: 0;
  min-width: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* If the title is (or contains) non-Latin script, replace the three
     rules above with:
       line-height: 1.8; overflow: visible; white-space: normal;
     — never truncate/clip a complex script for a short title. */
}

.brand-title-sub {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.theme-toggle {
  position: relative;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: var(--paper-raised);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.theme-toggle:active {
  transform: scale(0.94);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Theme toggle icon cross-fade — transform/opacity only (GPU-only rule),
   skipped entirely under prefers-reduced-motion below. */
.theme-icon {
  position: absolute;
  width: 1.1rem;
  height: 1.1rem;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.theme-icon--sun {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.theme-icon--moon {
  opacity: 0;
  transform: scale(0.5) rotate(-40deg);
}

html[data-theme="dark"] .theme-icon--sun {
  opacity: 0;
  transform: scale(0.5) rotate(40deg);
}

html[data-theme="dark"] .theme-icon--moon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-icon {
    transition: none;
  }
}

.masthead-sub {
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin: 0.6rem 0 0;
  max-width: 60ch;
}

/* ---------- Footer ---------- */

.page-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
}

.app-version {
  margin-top: 0.35rem;
  opacity: 0.6;
}

.app-version:empty {
  display: none;
}

/* ================= your content starts here ================== */

.workspace {
  max-width: 820px;
  margin: 2.5rem auto 0;
}

.preview-panel {
  text-align: center;
  margin-bottom: 1.5rem;
  padding: 0.85rem 1rem 1.25rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
}

.preview-top {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  min-height: 2.4rem;
}

.preview-top-spacer { flex: 1 1 auto; }

.toolbar--preview {
  margin: 0;
  justify-content: flex-end;
}

.preview-stage {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2rem;
  min-height: 130px;
  image-rendering: pixelated;
  flex-wrap: wrap;
}

.preview-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.preview-stage img {
  image-rendering: pixelated;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 2px;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  margin-top: 1rem;
}

.btn {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.85rem;
  min-height: 2.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  color: var(--ink);
  cursor: pointer;
}

.btn--sm {
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  min-height: 2rem;
}

.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
html[data-theme="dark"] .btn--primary { color: #1c1008; }

.status-line {
  margin: 0.6rem 0 0;
  min-height: 1.2em;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-faint);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 1.25rem;
  flex-wrap: wrap;
}

.picker-block--heads {
  margin-bottom: 1rem;
}

.toolbar-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.size-btn {
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.size-btn:hover { border-color: var(--accent); }
.size-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.size-value {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  min-width: 4.5rem;
  text-align: center;
  color: var(--ink-soft);
}

.block-title {
  font-size: 0.95rem;
  margin: 0 0 0.55rem;
  font-weight: 600;
}

.picker-block { margin-bottom: 1.35rem; }
.picker-block--flex { flex: 1 1 12rem; min-width: 0; }

.picker-grid {
  --icon-size: 19px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 14rem;
  overflow: auto;
  padding: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--paper-raised);
}

.picker-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
  line-height: 0;
}

.picker-btn img {
  width: var(--icon-size);
  height: var(--icon-size);
  image-rendering: pixelated;
  display: block;
}

.picker-btn.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.picker-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.part-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1.35rem;
  flex-wrap: wrap;
}

.nudge {
  flex: 0 0 auto;
  width: 7.5rem;
  text-align: center;
  padding: 0.65rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--paper-raised);
}

.nudge-title {
  margin: 0 0 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.nudge-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.nudge-mid {
  display: flex;
  gap: 0.2rem;
  align-items: center;
}

.nudge-btn {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
}

.nudge-btn:hover { border-color: var(--accent); }
.nudge-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.nudge-btn--flip { font-size: 0.9rem; }

.nudge-meta {
  margin: 0.45rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
}

.export-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.field input {
  font: inherit;
  font-size: 1rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  color: var(--ink);
  width: 100%;
}

.field input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.page-footer a { color: var(--accent); }

@media (max-width: 560px) {
  .part-row { flex-direction: column; }
  .nudge { width: 100%; }
  .picker-grid { max-height: 11rem; }
  .preview-top { justify-content: center; }
  .toolbar--preview { justify-content: center; width: 100%; }
  .preview-stage { gap: 1.25rem; }
}
