/* Fredoka (SIL Open Font License), zelf gehost zodat er geen externe lettertypedienst nodig is. */
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("fonts/fredoka-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #fbf7f2;
  --fg: #2b2118;
  --muted: #8a7a6a;
  --tile: #ffffff;
  --tile-border: #d8cfc4;
  --poop: #7a4a24;
  --poop-light: #a86b3c;
  --accent: #c98a4b;
  --key: #e8dfd4;
  --key-fg: #2b2118;
  --target: #efe6da;
  --danger: #b33a3a;
  --shadow: 0 8px 30px rgba(60, 35, 10, .18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1c1814;
    --fg: #f1e8de;
    --muted: #a39483;
    --tile: #2a241e;
    --tile-border: #4a3f34;
    --poop: #8f5a2e;
    --poop-light: #b77c47;
    --key: #3a322a;
    --key-fg: #f1e8de;
    --target: #2f2821;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1814;
  --fg: #f1e8de;
  --muted: #a39483;
  --tile: #2a241e;
  --tile-border: #4a3f34;
  --poop: #8f5a2e;
  --poop-light: #b77c47;
  --key: #3a322a;
  --key-fg: #f1e8de;
  --target: #2f2821;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Fredoka", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}
button { font: inherit; color: inherit; cursor: pointer; }

.topbar {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--tile-border);
}
.topbar h1 { font-family: var(--display); margin: 0; font-size: 1.8rem; letter-spacing: .04em; font-weight: 800; }
.topbar-right { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 2px solid var(--tile-border);
  background: transparent;
  font-weight: 700;
  font-size: 1.05rem;
}

main {
  width: 100%;
  max-width: 520px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px 12px;
  gap: 8px;
}

.modebar { display: flex; gap: 6px; background: var(--key); padding: 4px; border-radius: 999px; }
.mode-btn { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: .9rem; }
.mode-btn.active { background: var(--poop); color: #fff; }

.goal { margin: 2px 0; color: var(--muted); font-size: .95rem; }
.goal strong { color: var(--fg); }

.ladder {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  width: 100%;
  flex: 1;
  overflow-y: auto;
  min-height: 150px;
  padding: 4px 0;
}
.row { display: flex; gap: 6px; position: relative; }
.row .step {
  position: absolute; left: -34px; top: 50%; transform: translateY(-50%);
  font-size: .75rem; color: var(--muted); width: 26px; text-align: right;
}
.tile {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border: 2px solid var(--tile-border);
  background: var(--tile);
  font-family: var(--display);
  font-size: 1.7rem; font-weight: 600;
  text-transform: uppercase;
  border-radius: 6px;
  user-select: none;
}
.tile.hit { background: var(--poop); border-color: var(--poop); color: #fff; }
.tile.changed { box-shadow: inset 0 -4px 0 var(--accent); }
.tile.hit.changed { box-shadow: inset 0 -4px 0 #f0c48f; }
.row.input .tile { border-style: dashed; }
.row.input .tile.filled { border-style: solid; border-color: var(--muted); animation: pop .1s ease; }
.row.input .tile.cursor { border-color: var(--accent); border-style: solid; }
.row.input .tile.hint { background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(201, 138, 75, .25) 6px 12px); border-color: var(--accent); }
.row.target .tile { background: var(--target); border-color: transparent; color: var(--poop-light); opacity: .85; }
.row.start .tile:not(.hit) { border-color: var(--muted); }
.row.shake { animation: shake .35s; }
.row.win .tile { animation: bounce .5s ease both; }
.row.win .tile:nth-child(3) { animation-delay: .08s; }
.row.win .tile:nth-child(4) { animation-delay: .16s; }
.row.win .tile:nth-child(5) { animation-delay: .24s; }
.dots { color: var(--muted); font-size: 1.1rem; line-height: 1; }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes bounce { 40% { transform: translateY(-14px); } }

.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.action-btn {
  border: 1px solid var(--tile-border); background: transparent;
  padding: 6px 12px; border-radius: 8px; font-size: .9rem;
}
.action-btn:disabled { opacity: .4; cursor: default; }

.keyboard { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1; max-width: 44px; height: 54px;
  border: 0; border-radius: 6px;
  background: var(--key); color: var(--key-fg);
  font-weight: 700; font-size: 1rem; text-transform: uppercase;
  touch-action: manipulation;
}
.key.wide { max-width: 68px; flex: 1.5; font-size: .8rem; }
.key.target-letter { box-shadow: inset 0 -3px 0 var(--poop-light); }
.key:active { filter: brightness(.9); }

.dialog {
  border: 0; border-radius: 14px; padding: 24px 22px 20px;
  background: var(--bg); color: var(--fg);
  width: min(440px, calc(100% - 32px));
  box-shadow: var(--shadow);
  position: relative;
}
.dialog::backdrop { background: rgba(20, 12, 5, .5); }
.dialog h2 { margin-top: 0; }
.dialog ul { padding-left: 20px; }
.dialog li { margin-bottom: 6px; }
.close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 1.1rem; color: var(--muted); }
.small { font-size: .85rem; color: var(--muted); }
.example { display: flex; flex-direction: column; gap: 4px; align-items: center; margin: 12px 0; }
.mini-row { display: flex; gap: 4px; }
.mini-row span {
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 2px solid var(--tile-border); background: var(--tile); font-weight: 800; border-radius: 4px;
}
.mini-row span.hit, .swatch { background: var(--poop); border-color: var(--poop); color: #fff; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; }

.result-emoji { font-size: 3.5rem; text-align: center; }
#dlg-result h2 { text-align: center; margin: 4px 0; }
.result-sub { text-align: center; color: var(--muted); margin-top: 0; }
.paths { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.paths h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.path { margin: 0; padding-left: 0; list-style: none; font-family: ui-monospace, Menlo, monospace; font-weight: 700; letter-spacing: .12em; }
.path li { padding: 2px 0; }
.path li.p { color: var(--poop-light); }
.result-actions { display: flex; flex-direction: column; gap: 8px; }
.health-tip {
  display: flex; flex-direction: column; gap: 2px;
  margin: 0 0 12px; padding: 10px 12px;
  border: 1px solid var(--tile-border); border-radius: 10px;
  background: var(--target); color: var(--fg);
  font-size: .85rem; text-decoration: none;
}
.health-tip span { color: var(--muted); }
.health-tip:hover span { color: var(--poop-light); }
.primary-btn, .secondary-btn { padding: 12px; border-radius: 10px; font-weight: 700; border: 0; }
.primary-btn { background: var(--poop); color: #fff; }
.secondary-btn { background: var(--key); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 4px; }
.stats-grid b { display: block; font-size: 1.8rem; }
.stats-grid span { font-size: .75rem; color: var(--muted); }
.dist { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 6px; font-size: .85rem; }
.dist-row .lbl { width: 44px; text-align: right; color: var(--muted); }
.dist-row .bar { background: var(--key); padding: 2px 8px; border-radius: 4px; min-width: 24px; text-align: right; font-weight: 700; }
.dist-row .bar.cur { background: var(--poop); color: #fff; }

@media (max-height: 700px) {
  .tile { width: 44px; height: 44px; font-size: 1.4rem; }
  .key { height: 46px; }
}

.action-btn.armed { border-color: var(--danger); color: var(--danger); font-weight: 700; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.share-text {
  width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: .9rem;
  background: var(--tile); color: var(--fg); border: 1px solid var(--tile-border); border-radius: 8px; padding: 8px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
