:root {
  color-scheme: light dark;
  --bg: light-dark(#eeeeee, #202020);
  --text: light-dark(#111111, #eeeeee);
  --muted: light-dark(#626262, #b0b0b0);
  --line: light-dark(#a0a0a0, #555555);
  --tile-line: light-dark(#707070, #999999);
  --key: light-dark(#b5b5b5, #626262);
  --key-hover: light-dark(#a3a3a3, #787878);
  --match: light-dark(#d8c79d, #8b7546);
  --match-text: light-dark(#201b11, #ffffff);
  --panel: light-dark(#f7f7f7, #2b2b2b);
  --error: light-dark(#a52020, #ff9999);
  --focus: light-dark(#3265a0, #9cc7ff);
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
body { margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
button, input, textarea { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { opacity: .4; cursor: default; }
button, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; text-underline-offset: 3px; }
button:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.header { flex: none; height: 101px; position: relative; border-bottom: 1px solid var(--line); text-align: center; }
h1 { margin: 14px 0 12px; font-size: 2.5rem; line-height: 1.1; }
.puzzle-title { margin: 0; color: var(--muted); font-size: 1rem; }
.theme-button { position: absolute; top: 8px; right: 13px; border: 0; background: none; color: var(--muted); font-size: 1.4rem; padding: 4px 8px; }
.game { flex: 1; min-height: 0; width: min(100%, 430px); margin: 0 auto; display: flex; flex-direction: column; }
.play-area { flex: 1; min-height: 0; overflow-y: auto; padding: 55px 10px 12px; scrollbar-width: thin; }
#loading { text-align: center; color: var(--muted); font-size: .85rem; }
#board { display: flex; flex-direction: column; gap: 6px; }
.word-row { display: flex; justify-content: center; gap: 6px; }
.tile { width: 68px; height: 68px; flex: none; display: grid; place-items: center; border: 2px solid var(--tile-line); font-size: 2rem; font-weight: 700; }
.tile.matched { background: var(--match); color: var(--match-text); }
#word-form { width: fit-content; margin: 6px auto 0; }
.entry-row { position: relative; }
.entry-row:focus-within { outline: 2px solid var(--focus); outline-offset: 3px; }
#entry-tiles.invalid .tile { color: var(--muted); opacity: .55; }
#word { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: text; font-size: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.message { margin: 14px auto 0; min-height: 20px; max-width: 335px; text-align: center; font-size: .85rem; line-height: 1.5; color: var(--muted); }
.message.error { color: var(--error); }
.keyboard { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 0; }
.keyboard-row { display: flex; justify-content: center; gap: 5px; }
.key { border: 0; border-radius: 2px; background: var(--key); color: var(--text); height: 43px; padding: 0; min-width: 0; max-width: 35px; flex: 1; font-size: .95rem; font-weight: 700; }
.key:hover { background: var(--key-hover); }
.key.wide { flex: 1.5; max-width: 55px; font-size: .68rem; }
footer { width: min(100%, 430px); margin: 0 auto; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 10px max(15px, env(safe-area-inset-bottom)); }
footer > button, summary { border: 0; background: none; padding: 3px 0; color: var(--muted); font-size: .82rem; white-space: nowrap; }
footer > button:hover, summary:hover { color: var(--text); text-decoration: underline; }
details { position: relative; }
summary { cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
.more-menu { position: absolute; z-index: 2; right: 0; bottom: 35px; width: 180px; padding: 10px; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 3px 15px #0002; }
.more-menu button { display: block; border: 0; width: 100%; padding: 9px 7px; text-align: left; font-size: .85rem; background: none; }
.more-menu button:hover { background: var(--key); }
.more-menu button[aria-pressed="true"] { font-weight: 700; }
.move-count { display: block; color: var(--muted); padding: 5px 7px 10px; font-size: .8rem; }
.more-menu hr { border: 0; border-top: 1px solid var(--line); }
.finish { text-align: center; padding: 15px 0; }
.finish h2 { font-size: 1.3rem; margin: 0 0 10px; }
.finish p { font-size: .9rem; color: var(--muted); line-height: 1.6; }
.primary { border: 1px solid var(--tile-line); padding: 10px 14px; margin: 4px; background: var(--key); border-radius: 2px; font-size: .85rem; color: var(--text); }
.solution { text-align: center; font-size: .95rem; line-height: 2; margin: 20px 0; font-weight: 700; overflow-wrap: anywhere; }
dialog { color: var(--text); background: var(--panel); width: min(440px, calc(100% - 30px)); max-height: 85dvh; border: 1px solid var(--line); padding: 24px; border-radius: 3px; }
dialog::backdrop { background: #0008; }
.dialog-top { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.dialog-top h2 { margin: 0; font-size: 1.3rem; }
#close-dialog { border: 0; background: transparent; font-size: 1.7rem; padding: 0 3px; }
#dialog-content { font-size: .9rem; line-height: 1.7; color: var(--muted); }
#dialog-content strong { color: var(--text); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: center; margin: 24px 0; }
.stat { font-size: .75rem; }
.stat b { display: block; color: var(--text); font-size: 1.8rem; }
.share-copy { width: 100%; height: 140px; padding: 10px; background: var(--bg); color: var(--text); border: 1px solid var(--line); }
@media (max-width: 600px) {
  .header { height: 39px; display: flex; align-items: center; justify-content: space-between; padding: 0 48px 0 9px; gap: 15px; }
  h1 { margin: 0; font-size: 1.05rem; }
  .puzzle-title { font-size: .9rem; }
  .theme-button { top: 1px; right: 5px; font-size: 1.2rem; }
  .tile { width: 63px; height: 63px; }
  .key { height: 43px; font-size: .85rem; }
  .keyboard-row { gap: 5px; }
  footer { gap: 7px; }
  footer > button, summary { font-size: .8rem; }
}
@media (max-width: 350px) {
  .tile { width: 59px; height: 59px; }
  .play-area { padding-top: 40px; }
  footer > button, summary { font-size: .73rem; }
  .key { font-size: .75rem; }
  .key.wide { font-size: .6rem; }
  .keyboard-row { gap: 4px; }
}
@media (max-height: 540px) {
  .header { height: 39px; }
  h1 { margin: 7px; font-size: 1.1rem; }
  .puzzle-title { position: absolute; top: 10px; left: 12px; font-size: .8rem; }
  .play-area { padding-top: 14px; }
  .tile { width: 45px; height: 45px; font-size: 1.5rem; }
  .key { height: 33px; }
  footer { padding-top: 9px; padding-bottom: 9px; }
}
