/* Orokin Lexicon
   Ivory page, gold accents, black glyphs: the palette of the reference chart and the icon.
   Cormorant Garamond is used only where it is large (the wordmark and the English
   translation); everything else uses the system sans. */

:root {
  color-scheme: light;
  --bg: #f3eee3;
  --sheet: #fffdf8;
  --ink: #26221c;
  --muted: #72675a;
  --line: #e0d5bf;
  --line-strong: #cdbd9b;
  --rule: #c6a55a;
  --gold: #976e17;
  --glyph: #1d1914;
  --hover: #faf3e2;
  --close: #b7791f;
  --sounds: #94468f;
  --danger: #a33a2a;
  --serif: "Cormorant Garamond", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 2px;
}
/* Light by default; dark only when chosen with the toggle. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131210; --sheet: #1d1b18; --ink: #ece5d6; --muted: #a39a88; --line: #35312a;
  --line-strong: #4a4439; --rule: #7d6530; --gold: #e0b95a; --glyph: #f0d48c; --hover: #27231c;
  --close: #e6a94a; --sounds: #d59ad5; --danger: #e0806f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}
button { font: inherit; color: inherit; }
body[data-mode="glyphs"] .english-only, body[data-mode="english"] .glyph-only { display: none; }
[hidden] { display: none !important; }

/* ---------- masthead ---------- */

.masthead {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 24px;
}
.masthead::after {
  content: "";
  flex-basis: 100%;
  height: 4px;
  margin-top: 12px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.masthead h1 {
  display: inline-flex;
  align-items: center;
  gap: .25em;
  margin: 0;
  font: 600 clamp(30px, 3.6vw, 40px)/1 var(--serif);
  color: var(--gold);
  white-space: nowrap;
}
.logo { width: .95em; height: .95em; flex: none; }
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }
.subtitle cite { font-style: italic; }

.modes { position: relative; display: flex; gap: 4px; margin-left: auto; padding: 3px; background: var(--line); border-radius: var(--radius); }
/* The highlight behind the selected direction slides between the two options. */
.modes-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: var(--thumb-w, 0);
  transform: translateX(var(--thumb-x, 0));
  background: var(--sheet);
  border-radius: 1px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
  transition: transform .32s cubic-bezier(.3, .8, .25, 1), width .32s cubic-bezier(.3, .8, .25, 1);
}
.modes.no-anim .modes-thumb { transition: none; }
.modes button {
  border: 0;
  background: none;
  border-radius: 1px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}
.modes button:hover { color: var(--ink); }
.modes button { position: relative; z-index: 1; transition: color .25s; }
.modes button[aria-selected="true"] { color: var(--ink); }
.modes button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.install { flex-basis: 100%; text-align: left; }

.theme-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); background: var(--hover); }
.theme-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* Sun and moon sit on top of each other and swap with a turn and a fade. */
.theme-toggle { position: relative; overflow: hidden; }
.theme-toggle svg {
  position: absolute;
  inset: 0;
  margin: auto;
  transition: transform .45s cubic-bezier(.3, .8, .25, 1), opacity .3s;
}
.theme-toggle .sun { opacity: 0; transform: rotate(-90deg) scale(.4); }
:root[data-theme="dark"] .theme-toggle .sun { opacity: 1; transform: none; }
:root[data-theme="dark"] .theme-toggle .moon { opacity: 0; transform: rotate(90deg) scale(.4); }

/* While switching theme, colours ease across instead of snapping. */
:root.theme-anim *, :root.theme-anim *::before, :root.theme-anim *::after {
  transition: background-color .35s, color .35s, border-color .35s, fill .35s, stroke .35s, box-shadow .35s !important;
}
:root.theme-anim .theme-toggle svg { transition: transform .45s cubic-bezier(.3, .8, .25, 1), opacity .3s, stroke .35s !important; }

@media (prefers-reduced-motion: reduce) {
  .modes-thumb, .modes button, .theme-toggle svg { transition: none !important; }
  :root.theme-anim *, :root.theme-anim *::before, :root.theme-anim *::after { transition: none !important; }
}

.text-btn {
  border: 0;
  background: none;
  padding: 2px 0;
  cursor: pointer;
  color: var(--gold);
  font-size: 13px;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
}
.text-btn:hover { text-decoration-color: currentColor; }
.text-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- desk: writing on the left, keyboard on the right ---------- */

.desk {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 8px;
  display: grid;
  gap: 24px 36px;
}
body[data-mode="glyphs"] .desk {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "reading keyboard" "notes keyboard";
  align-items: start;
}
.reading { grid-area: reading; min-width: 0; }
.notes { grid-area: notes; }
.keyboard { grid-area: keyboard; min-width: 0; }

/* The rules you need while typing, kept beside the writing rather than behind a toggle. */
.notes { padding-top: 16px; border-top: 1px solid var(--line); max-width: 58ch; }
.notes ol { list-style: none; counter-reset: rule; margin: 10px 0 0; padding: 0; }
.notes li {
  counter-increment: rule;
  position: relative;
  padding-left: 28px;
  margin: 0 0 9px;
  font-size: 14px;
  line-height: 1.45;
}
.notes li::before {
  content: counter(rule);
  position: absolute;
  left: 0;
  top: -3px;
  font: 600 20px/1 var(--serif);
  font-variant-numeric: lining-nums;
  color: var(--gold);
}
.notes em { font-style: normal; font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
body[data-mode="english"] .desk { max-width: 920px; grid-template-columns: minmax(0, 1fr); grid-template-areas: "reading"; }

/* One label style for every section heading. */
h2, h3 {
  margin: 0;
  font: 600 11.5px/1.3 var(--sans);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
h3 span { margin-left: 6px; font-weight: 400; letter-spacing: 0; text-transform: none; font-size: 12.5px; }

.head-actions { display: inline-flex; gap: 16px; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toggle { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.toggle input { accent-color: var(--gold); margin: 0; }
.leaf + .leaf { margin-top: 20px; }

.tablet {
  position: relative;
  margin-top: 8px;
  min-height: 200px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  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; }
.empty {
  position: absolute; inset: 0; margin: 0;
  display: grid; place-items: center;
  color: var(--muted); font-size: 14px;
  pointer-events: none;
}
.phonetic {
  margin: 6px 2px 0;
  min-height: 1.5em;
  font: 12.5px/1.5 var(--mono);
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.english {
  margin-top: 4px;
  font: 500 clamp(28px, 2.6vw, 34px)/1.25 var(--serif);
  min-height: 1.25em;
  overflow-wrap: anywhere;
}
.examples { margin: 6px 0 0; font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.examples .text-btn { font-size: 14px; }
.word { border: 0; background: none; padding: 0; font: inherit; }
.word.close { text-decoration: underline dotted var(--close) 2px; text-underline-offset: 6px; }
.word.sounds { color: var(--sounds); font-style: italic; }
.word.alt { cursor: pointer; box-shadow: inset 0 -2px var(--rule); }
.word.alt:hover, .word.alt:focus-visible { background: var(--hover); outline: none; }
.legend { margin: 8px 0 0; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 16px; }
.legend:not(:has(span:not([hidden]))) { display: none; }
.swatch { display: inline-block; width: 16px; height: 0; margin-right: 6px; vertical-align: middle; }
.swatch.close { border-bottom: 2px dotted var(--close); }
.swatch.sounds { border-bottom: 2px solid var(--sounds); }
.swatch.alt { border-bottom: 2px solid var(--rule); }

/* ---------- English → Orokin input ---------- */

.compose { margin-bottom: 20px; }
textarea {
  width: 100%;
  margin-top: 8px;
  padding: 10px 14px;
  font: 500 26px/1.3 var(--serif);
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
textarea::placeholder { color: var(--muted); font-style: italic; }
.status { margin: 6px 0 0; font-size: 13px; color: var(--muted); min-height: 1.3em; }

.breakdown {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
}
.breakdown li { font-size: 14px; min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.breakdown b { font: 600 19px var(--serif); margin-right: 6px; }
.breakdown code { font: 12px var(--mono); color: var(--muted); }
.breakdown li.guess code { color: var(--sounds); }
.breakdown li.guess b::after { content: "*"; color: var(--sounds); margin-left: 1px; }

/* ---------- keyboard ---------- */

.key-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  min-height: 44px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
.key-info .specimen { flex: none; fill: var(--glyph); }
.key-info b { color: var(--ink); font-size: 16px; margin-right: -6px; }

.keyboard h3 { margin: 16px 0 7px; }
.keyboard h3:first-of-type { margin-top: 0; }

.keys { display: grid; gap: 6px; }
.keys.vowels { grid-template-columns: repeat(11, minmax(0, 1fr)); }
/* Nine columns, as in the chart: each notched glyph sits under the glyph it comes from. */
.keys.consonants { grid-template-columns: repeat(9, minmax(0, 1fr)); }
.keys.consonants [data-glyph="m"] { grid-column: 1; }
.keys.digits { grid-template-columns: repeat(10, minmax(0, 1fr)); }

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  height: 60px;
  padding: 4px 2px;
  background: var(--sheet);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color .1s, border-color .1s;
}
.key:hover { background: var(--hover); border-color: var(--rule); }
.key:active { background: var(--line); }
.key:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.key .art { flex: 1; min-height: 0; display: grid; place-items: center; }
.key svg { display: block; fill: var(--glyph); max-width: 100%; height: auto; }
.key .name { font-weight: 600; font-size: 12px; line-height: 1; }
.key .hint { display: none; }
.digits .key { height: 52px; }

.bottom-row { display: flex; gap: 6px; margin-top: 6px; }
.keys.punct { grid-template-columns: repeat(3, 84px); flex: none; }
.punct .key { height: 52px; }
.controls { display: flex; gap: 6px; flex: 7; }
.ctl {
  height: 52px;
  padding: 0 14px;
  background: var(--sheet);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.ctl.space { flex: 1; }
.ctl:hover { background: var(--hover); border-color: var(--rule); }
.ctl:active { background: var(--line); }
.ctl:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.ctl.danger { color: var(--danger); }
.ctl[data-action="backspace"] { font-size: 18px; min-width: 56px; }


/* ---------- about ---------- */

.about { max-width: 1200px; margin: 20px auto 40px; padding: 0 24px; }
.about summary {
  cursor: pointer;
  padding: 12px 0;
  border-top: 1px solid var(--line-strong);
  font-weight: 600;
  color: var(--gold);
}
.about summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.about-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 32px; align-items: start; }
.about ol { margin: 0; padding-left: 22px; max-width: 60ch; }
.about li { margin: 0 0 10px; }
.about figure { margin: 0; }
.about img { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.about figcaption { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- narrower screens ---------- */

@media (max-width: 1080px) {
  body[data-mode="glyphs"] .desk {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "reading" "keyboard" "notes";
  }
  /* Keep the writing in view while typing: the reading pane pins to the top and scrolls itself. */
  body[data-mode="glyphs"] .reading {
    position: sticky;
    top: 0;
    z-index: 2;
    max-height: 42vh;
    overflow-y: auto;
    margin: 0 -24px;
    padding: 10px 24px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--line-strong);
  }
}

@media (max-width: 640px) {
  .masthead { padding: 14px 16px 0; gap: 8px 16px; }
  .masthead::after { margin-top: 4px; }
  .subtitle { display: none; }
  .modes { margin-left: 0; flex: 1; }
  .modes button { flex: 1; }
  .desk { padding: 12px 16px 8px; }
  body[data-mode="glyphs"] .reading { margin: 0 -16px; padding: 8px 16px 10px; max-height: 38vh; }
  .tablet { min-height: 110px; }
  .english { font-size: 26px; }
  .key-info { display: none; }
  .keyboard h3 span { display: none; }
  .keys { gap: 5px; }
  .keys.vowels { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .keys.consonants { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .keys.consonants [data-glyph="m"] { grid-column: auto; }
  .keys.digits { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .key { height: 54px; }
  .digits .key, .punct .key { height: 48px; }
  .bottom-row { margin-top: 5px; }
  .keys.punct { flex: 1; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* Space, delete and clear become a bar at the bottom of the screen, under the thumb. */
  body[data-mode="glyphs"] { padding-bottom: 72px; }
  .controls {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 3;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--line-strong);
  }
  .ctl { height: 48px; }
  .about { padding: 0 16px; }
  .about-body { grid-template-columns: 1fr; gap: 16px; }
}
