/* Oghamle — styled to match oghamlore.com (cream / stone / forest / earth) */

@font-face {
  font-family: 'BabelStoneOgham';
  src: url('/fonts/BabelStoneOghamR.woff2') format('woff2');
  font-display: block;
}

:root {
  --cream: #f5f0e8;
  --stone: #f0e8d8;
  --stone-100: #f5f5f4;
  --stone-200: #e7e5e4;
  --stone-300: #d6d3d1;
  --stone-400: #a8a29e;
  --stone-500: #78716c;
  --stone-700: #44403c;
  --stone-800: #292524;
  --forest: #2d5a27;
  --forest-dark: #1a3a16;
  --forest-light: #4a7c43;
  --earth: #8b6914;
  --earth-light: #c49a2a;
  --danger: #a33a2a;

  /* Tile states */
  --correct: var(--forest-light);
  --present: var(--earth-light);
  --absent: #8a8275;

  --font-serif: Georgia, Cambria, 'Times New Roman', serif;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Uncial Antiqua', Georgia, serif;
  --font-ogham: 'BabelStoneOgham', 'Noto Sans Ogham', 'Segoe UI Historic', sans-serif;

  --cols: 6;
  --rows: 6;
  --gap: 5px;
  /* Tile size: fits the width, and leaves room for header + keyboard in height */
  --tile: min(3.6rem,
              calc((100vw - 2rem - (var(--cols) - 1) * var(--gap)) / var(--cols)),
              calc((100dvh - 25.5rem - (var(--rows) - 1) * var(--gap)) / var(--rows)));
  --key-h: 3.5rem;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--cream);
  color: var(--stone-800);
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--forest); }
.hidden { display: none !important; }
.muted { color: var(--stone-500); font-size: .875rem; }
.center { text-align: center; }

/* ---------- Layout ---------- */
.layout { display: flex; justify-content: center; min-height: 100dvh; }
.side-ad { display: none; width: 12rem; flex-shrink: 0; padding: 1rem; }
@media (min-width: 1024px) { .side-ad { display: block; } }
@media (min-width: 1280px) { .side-ad { width: 16rem; } }

.app {
  width: 100%;
  max-width: 34rem;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Header (matches site nav: stone bar w/ border) ---------- */
.topbar {
  display: grid;
  grid-template-columns: 5.5rem 1fr 5.5rem;
  align-items: center;
  background: var(--stone);
  border-bottom: 1px solid var(--stone-300);
  padding: calc(.4rem + env(safe-area-inset-top)) .75rem .4rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
@media (min-width: 34rem) { .topbar { border-radius: 0 0 12px 12px; border: 1px solid var(--stone-300); border-top: 0; } }
.topbar-side { display: flex; gap: .25rem; }
.topbar-side.right { justify-content: flex-end; }
.icon-btn {
  width: 2.5rem; height: 2.5rem;
  display: grid; place-items: center;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--stone-700);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--stone-100); color: var(--forest); }
.icon-btn svg { width: 1.5rem; height: 1.5rem; }

.title { margin: 0; text-align: center; line-height: 1.05; }
.title-ogham { display: block; font-family: var(--font-ogham); font-size: 1.1rem; color: var(--earth); letter-spacing: .05em; }
.title-latin { display: block; font-family: var(--font-display); font-weight: 400; font-size: 1.6rem; color: var(--forest-dark); }

.top-ad { height: 60px; overflow: hidden; margin: .5rem 1rem 0; text-align: center; }
.top-ad:empty, .top-ad ins[data-ad-status="unfilled"] { display: none; }

/* ---------- Board ---------- */
.board-area { flex: 1; display: grid; place-items: center; padding: .75rem 1rem; }
.board { display: flex; flex-direction: column; gap: var(--gap); }
.loading { font-family: var(--font-serif); font-style: italic; color: var(--stone-500); }

.row { display: flex; gap: var(--gap); }

.tile {
  width: var(--tile);
  height: var(--tile);
  display: inline-grid;
  place-items: center;
  font-family: var(--font-ogham);
  font-size: calc(var(--tile) * .62);
  line-height: 1;
  color: var(--stone-800);
  background: #fffdf8;
  border: 2px solid var(--stone-300);
  border-radius: 6px;
  user-select: none;
}
.tile.filled { border-color: var(--stone-500); animation: pop .1s ease-in-out; }
.tile.correct, .tile.present, .tile.absent { color: #fff; }
.tile.correct { background: var(--correct); border-color: var(--correct); }
.tile.present { background: var(--present); border-color: var(--present); }
.tile.absent  { background: var(--absent);  border-color: var(--absent); }

/* Ogham glyph inside the tile, so we can rotate it independently of tile animations */
.tile .glyph { display: block; position: relative; z-index: 1; height: 1em; line-height: 1; transition: transform .3s ease; }

/* ---------- Continuous stem line ----------
   U+1680 OGHAM SPACE MARK is the stem line on its own. Drawn in the same font,
   size and line box as each letter, a run of them sits exactly on every glyph's
   stem, so we extend it to the tile edges and run it behind the row through the gaps. */
:root { --stem: '\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680\1680'; }
.row, .tile { position: relative; }
.stem-line .tile .glyph::before,
.stem-line .row::before {
  content: var(--stem);
  position: absolute;
  top: 50%;
  left: 50%;
  height: 1em;
  line-height: 1;
  font-family: var(--font-ogham);
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
}
/* Inside a tile: edge to edge, behind the letter, in the tile's text colour */
.stem-line .tile .glyph::before { width: var(--tile); transform: translate(-50%, -50%); z-index: -1; }
.stem-line .tile:not(.filled) .glyph::before { color: var(--stone-300); }
/* Behind the row: shows through the gaps between tiles */
.stem-line .row::before {
  font-size: calc(var(--tile) * .62);
  width: calc(var(--cols) * var(--tile) + (var(--cols) - 1) * var(--gap));
  transform: translate(-50%, -50%);
  color: var(--stone-400);
}
.stem-line.stone-mode .row::before { transform: translate(-50%, -50%) rotate(-90deg); }

.tile.flip { animation: flip .5s ease-in-out; }
.tile.win  { animation: bounce 1s ease-in-out; }
.row.shake { animation: shake .5s; }

@keyframes pop    { 50% { transform: scale(1.1); } }
@keyframes flip   { 0%, 100% { transform: rotateX(0); } 50% { transform: rotateX(-90deg); } }
@keyframes shake  { 10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); } 20%, 40%, 60%, 80% { transform: translateX(5px); } }
@keyframes bounce {
  0%, 20% { transform: translateY(0); } 40% { transform: translateY(-24px); }
  50% { transform: translateY(4px); } 60% { transform: translateY(-12px); }
  80% { transform: translateY(2px); } 100% { transform: translateY(0); }
}

/* ---------- Stone (column) layout ----------
   Each guess becomes a vertical stem read bottom → top, glyphs rotated so the
   stem-line runs vertically like an inscription. */
.stone-mode .board { flex-direction: row; }
.stone-mode .row { flex-direction: column-reverse; }
.stone-mode .row.shake { animation-name: shake-y; }
.stone-mode .tile .glyph,
.stone-mode .key .ogham { transform: rotate(-90deg); }
@keyframes shake-y { 10%, 30%, 50%, 70%, 90% { transform: translateY(-5px); } 20%, 40%, 60%, 80% { transform: translateY(5px); } }
.stone-mode { --tile: min(3.6rem,
              calc((100vw - 2rem - (var(--rows) - 1) * var(--gap)) / var(--rows)),
              calc((100dvh - 25.5rem - (var(--cols) - 1) * var(--gap)) / var(--cols))); }

/* ---------- Keyboard ---------- */
.keyboard { padding: .25rem .375rem .75rem; user-select: none; }
.kb-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 6px; }
.key {
  flex: 1 1 0;
  max-width: 3.25rem;
  height: var(--key-h);
  border: 0;
  border-radius: 6px;
  background: var(--stone-200);
  color: var(--stone-800);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  padding: 0;
  touch-action: manipulation;
  transition: background .15s, transform .05s;
}
.key:hover { background: var(--stone-300); }
.key:active { transform: scale(.95); }
.key .ogham { font-family: var(--font-ogham); font-size: 1.6rem; line-height: 1; transition: transform .3s ease; }
.key .latin { font-size: .65rem; font-weight: 600; opacity: .7; letter-spacing: .03em; }
.hide-latin .key .latin { display: none; }
.hide-latin .key .ogham { font-size: 1.9rem; }
.key.wide { flex-grow: 1.6; max-width: 5rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.key.enter { background: var(--forest); color: var(--cream); }
.key.enter:hover { background: var(--forest-dark); }
.key.wide svg { width: 1.4rem; height: 1.4rem; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent  { background: var(--absent);  color: #fff; opacity: .75; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; top: 5rem; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .5rem; align-items: center;
  z-index: 100; pointer-events: none;
}
.toast {
  background: var(--forest-dark); color: var(--cream);
  padding: .6rem 1rem; border-radius: 8px;
  font-weight: 600; font-size: .9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: toast-in .15s ease-out;
}
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- Modals (native <dialog>) ---------- */
.modal {
  width: min(30rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--stone-300);
  border-radius: 12px;
  background: #fffdf8;
  color: var(--stone-800);
  box-shadow: 0 20px 50px rgba(26,58,22,.25);
}
.modal::backdrop { background: rgba(26, 58, 22, .45); backdrop-filter: blur(2px); }
.modal[open] { animation: modal-in .2s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-small { width: min(22rem, calc(100vw - 2rem)); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--stone-200);
  background: var(--stone);
}
.modal h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.4rem; color: var(--forest-dark); }
.modal h3 { font-family: var(--font-serif); font-size: 1.05rem; color: var(--forest-dark); margin: 1.25rem 0 .5rem; }
.modal-close { border: 0; background: transparent; font-size: 1.75rem; line-height: 1; padding: 0 .25rem; color: var(--stone-500); }
.modal-close:hover { color: var(--forest); }
.modal-body { padding: 1.25rem; }
.prose { font-size: .925rem; line-height: 1.55; }
.prose p { margin: 0 0 .75rem; }
.example { display: flex; align-items: center; gap: .75rem; margin: .5rem 0; font-size: .9rem; }
.example .tile { --tile: 2.25rem; flex-shrink: 0; }
kbd { background: var(--stone-200); border-radius: 4px; padding: 1px 6px; font-size: .8rem; font-family: var(--font-sans); }

.result-message { font-family: var(--font-serif); font-size: 1.2rem; font-weight: 700; margin: 0 0 .5rem; }
.result-message.win { color: var(--forest); }
.reveal-ogham { font-family: var(--font-ogham); font-size: 2.5rem; margin: .25rem 0; color: var(--forest-dark); }
.reveal-latin { font-family: var(--font-serif); font-size: 1.3rem; font-weight: 700; letter-spacing: .2em; margin: 0 0 .5rem; }
.daily-message {
  margin: 1rem 0; padding: 1rem; text-align: left;
  background: var(--stone); border-left: 4px solid var(--earth-light); border-radius: 6px;
  font-size: .925rem; line-height: 1.6;
}
.daily-message:empty { display: none; }
.daily-message a { color: var(--forest); font-weight: 600; text-underline-offset: 2px; }
.countdown { font-size: .9rem; color: var(--stone-500); margin-bottom: 1rem; }
.countdown strong { font-variant-numeric: tabular-nums; color: var(--stone-800); }

.btn {
  border: 0; border-radius: 999px; padding: .7rem 1.5rem;
  font-weight: 600; font-size: .95rem; transition: background .15s;
}
.btn-primary { background: var(--forest); color: var(--cream); }
.btn-primary:hover { background: var(--forest-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #7f2b1f; }
.btn-ghost { background: var(--stone-200); }
.btn-ghost:hover { background: var(--stone-300); }
.btn-row { display: flex; gap: .75rem; justify-content: center; margin-top: 1rem; }

/* Stats */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; text-align: center; }
.stat span { display: block; font-family: var(--font-serif); font-size: 2rem; font-weight: 700; color: var(--forest-dark); }
.stat small { font-size: .72rem; color: var(--stone-500); line-height: 1.2; display: block; }
.distribution { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.dist-row > span { width: 1rem; text-align: right; font-weight: 600; }
.dist-bar {
  min-width: 1.75rem; padding: 2px 8px; text-align: right;
  background: var(--absent); color: #fff; font-weight: 700; border-radius: 3px;
  transition: width .4s ease;
}
.dist-bar.current { background: var(--correct); }

/* Settings */
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 0; border-bottom: 1px solid var(--stone-200); cursor: pointer;
}
.setting small { display: block; color: var(--stone-500); font-size: .8rem; }
.switch {
  appearance: none; flex-shrink: 0;
  width: 2.75rem; height: 1.5rem; border-radius: 999px;
  background: var(--stone-300); position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 1.125rem; height: 1.125rem; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s;
}
.switch:checked { background: var(--forest); }
.switch:checked::after { transform: translateX(1.25rem); }
.switch:focus-visible, .btn:focus-visible, .key:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--earth-light); outline-offset: 2px; }
.danger-zone { margin-top: 1.5rem; }
.danger-zone .muted { margin: .5rem 0 0; }

/* ---------- Embed & recording modes ---------- */
.embed-credit, .recording-only { display: none; }
.recording .recording-only { display: flex; }

/* Embedded in an iframe: no ads, no install, compact header, small credit link */
.embed .layout, .embed .app { min-height: 100vh; min-height: 100dvh; }
.embed #installButton { display: none !important; }
.embed .topbar { position: static; padding-top: .4rem; border-radius: 0; border-left: 0; border-right: 0; }
.embed .embed-share { display: none; }
.embed .embed-credit {
  display: block; text-align: center; font-size: .75rem; color: var(--stone-500);
  text-decoration: none; padding: 0 0 .5rem;
}
.embed .embed-credit strong { color: var(--forest); }

/* Recording: nothing that isn't the game */
.recording #installButton { display: none !important; }

.embed-share { padding: .5rem 0 .25rem; border-bottom: 1px solid var(--stone-200); }
.embed-share h3 { margin-top: .75rem; }
.embed-share .muted { margin: 0 0 .5rem; }
.embed-code {
  width: 100%; resize: none; margin-bottom: .5rem;
  font: .75rem/1.4 ui-monospace, Consolas, monospace;
  color: var(--stone-700); background: var(--stone);
  border: 1px solid var(--stone-300); border-radius: 6px; padding: .5rem;
}

/* Confetti canvas */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 1000; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Forfeda row: the four keys sit centred under the main rows */
.kb-row:last-child .key { max-width: 3.6rem; }
.key .latin:where(:not(:empty)) { white-space: nowrap; }
.ogham-inline { font-family: var(--font-ogham); font-size: 1.15em; }
