:root {
  --bg: #f4efe4;
  --panel: #fffdf8;
  --ink: #2a2620;
  --muted: #7a7061;
  --line: #e2d8c3;
  --gold: #a57a1f;
  --gold-soft: #d9b86a;
  --glyph: #1f1b16;
  --key: #fbf7ee;
  --key-hover: #f3e8cf;
  --close: #b7791f;
  --sounds: #9b4d9b;
  --danger: #a33a2a;
  --shadow: 0 1px 2px rgba(60, 45, 20, .08), 0 6px 20px rgba(60, 45, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121110;
    --panel: #1b1a17;
    --ink: #ece5d6;
    --muted: #a39a88;
    --line: #34302a;
    --gold: #e0b95a;
    --gold-soft: #8f7433;
    --glyph: #f0d48c;
    --key: #221f1b;
    --key-hover: #2f2a21;
    --close: #e6a94a;
    --sounds: #d59ad5;
    --danger: #e0806f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #121110; --panel: #1b1a17; --ink: #ece5d6; --muted: #a39a88; --line: #34302a;
  --gold: #e0b95a; --gold-soft: #8f7433; --glyph: #f0d48c; --key: #221f1b; --key-hover: #2f2a21;
  --close: #e6a94a; --sounds: #d59ad5; --danger: #e0806f; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
button { font: inherit; color: inherit; }

.top { text-align: center; padding: 28px 16px 8px; }
.top h1 {
  font-family: Cinzel, Georgia, serif;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--gold);
  margin: 0;
  font-size: clamp(26px, 5vw, 40px);
}
.tagline { margin: 4px 0 0; color: var(--muted); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h2, h3 { font-family: Cinzel, Georgia, serif; font-weight: 500; letter-spacing: .06em; margin: 0; }
h2 { font-size: 18px; color: var(--gold); }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--ink); }
h3 small { font-family: Inter, system-ui, sans-serif; font-size: 12px; letter-spacing: 0; color: var(--muted); font-weight: 400; margin-left: 6px; }

.toggle { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.toggle input { accent-color: var(--gold); }

.tablet {
  position: relative;
  margin-top: 10px;
  min-height: 150px;
  border-radius: 10px;
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box,
    linear-gradient(135deg, var(--gold-soft), transparent 40%, transparent 60%, var(--gold-soft)) border-box;
  border: 1px solid transparent;
  overflow: hidden;
}
.tablet svg { display: block; max-width: 100%; height: auto; }
.tablet .glyph { fill: var(--glyph); }
.tablet .glyph.faint { opacity: .4; }
.tablet .guide { stroke: var(--line); stroke-width: 1; stroke-dasharray: 4 6; }
.tablet .caret { fill: var(--gold); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.empty { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.phonetic {
  margin: 8px 0 0;
  min-height: 1.5em;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.english {
  margin-top: 8px;
  font-size: clamp(22px, 3.6vw, 30px);
  line-height: 1.45;
  min-height: 1.5em;
  overflow-wrap: anywhere;
}
.english .placeholder { color: var(--muted); font-size: 18px; }
.word { border: 0; background: none; padding: 0; font-size: inherit; line-height: inherit; }
.word.close { text-decoration: underline dotted var(--close) 2px; text-underline-offset: 5px; }
.word.sounds { color: var(--sounds); font-style: italic; }
.word.alt { cursor: pointer; border-bottom: 2px solid var(--gold-soft); border-radius: 2px; }
.word.alt:hover, .word.alt:focus-visible { background: var(--key-hover); outline: none; }
.legend { margin: 10px 0 0; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.swatch { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin-right: -8px; }
.swatch.close { border-bottom: 2px dotted var(--close); }
.swatch.sounds { border-bottom: 2px solid var(--sounds); }
.swatch.alt { border-bottom: 2px solid var(--gold-soft); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ctl, .ghost {
  border: 1px solid var(--line);
  background: var(--key);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.ctl:hover, .ghost:hover { background: var(--key-hover); }
.ctl.danger { color: var(--danger); }
.ghost { padding: 5px 10px; font-size: 13px; }
.examples { margin-left: auto; color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.keys { display: grid; gap: 8px; }
.keys.vowels { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
.keys.consonants { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); }
.keys.digits { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); }
.keys.punct { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.split { display: grid; grid-template-columns: 3fr 2fr; gap: 0 20px; }

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--key);
  cursor: pointer;
  transition: background .12s, transform .06s, border-color .12s;
  min-width: 0;
}
.key:hover { background: var(--key-hover); border-color: var(--gold-soft); }
.key:active { transform: translateY(1px) scale(.98); }
.key:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.key .art { height: 48px; display: grid; place-items: center; }
.key svg { display: block; fill: var(--glyph); max-width: 100%; height: auto; }
.key .name { font-weight: 600; font-size: 14px; }
.key .hint { font-size: 11px; color: var(--muted); line-height: 1.2; text-align: center; min-height: 1.2em; }
.digits .key .hint, .digits .key .hint:empty { display: none; }

.help summary { cursor: pointer; font-family: Cinzel, Georgia, serif; color: var(--gold); letter-spacing: .05em; }
.help ul { padding-left: 20px; }
.help li { margin: 6px 0; }
.help img { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--line); background: #fff; }

@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .split { grid-template-columns: 1fr; }
  .examples { margin-left: 0; }
  .keys.consonants { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .key .art { height: 40px; }
}
