:root {
  color-scheme: dark;
  --page: #121213;
  --panel: #202021;
  --control: #2d2d30;
  --field: #353538;
  --hover: #404044;
  --focus: #505057;
  --text: #fff;
  --muted: #bbb;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  font-family: Arial, "Helvetica Neue", sans-serif;
  background: var(--page);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; }
button, input, textarea, dialog { border: 0; border-radius: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
:is(button, input, textarea, a, .board):focus-visible { outline: none; }
button:focus-visible { background: var(--focus); text-decoration: underline; }
a:focus-visible { background: var(--focus); color: var(--text); }

.masthead {
  position: fixed;
  z-index: 1;
  top: 24px;
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 6px;
  transform: translateX(-50%);
}
h1 { margin: 0; font-size: 1.65rem; line-height: 1.15; }
.masthead strong { font-size: 1.3rem; }
.masthead span { color: var(--muted); font-size: .8125rem; }
.help, .home {
  position: fixed;
  z-index: 2;
  top: 24px;
  right: 24px;
  width: 36px;
  height: 36px;
  background: var(--control);
  font-weight: 700;
}
.home { right: 68px; width: auto; padding-inline: 10px; font-size: .8125rem; }
.home:hover { background: var(--hover); }

.menu-shell { display: grid; min-height: 100dvh; place-items: center; padding: 70px 18px 38px; }
.menu-panel { width: min(100%, 410px); }
.menu-panel h1 { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.menu-panel h1:focus { outline: none; }
#menu-title {
  min-height: 64px;
  margin-bottom: 0;
  padding: 12px 14px;
  background: var(--panel);
  font-size: 1.85rem;
}
.logo-tile {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: var(--correct);
  font-weight: 800;
  font-size: 1.25rem;
}
.menu-options { display: grid; gap: 2px; }
.menu-option {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 65px;
  padding: 10px 14px;
  background: var(--control);
  text-align: left;
}
.menu-option:hover, .secondary-button:hover { background: var(--hover); }
.menu-option:focus-visible, .secondary-button:focus-visible { background: var(--focus); }
.menu-option:active, .action-button:active { background: #454c44; }
.menu-option small { display: block; margin-top: 4px; color: var(--muted); font-size: .8125rem; }
.option-icon {
  flex: 0 0 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: #212124;
}
.menu-option:first-child .option-icon { background: #375c33; }
.option-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.menu-option:first-child .option-icon path { fill: currentColor; }
.setup-panel, .history-panel { padding: 20px; background: var(--panel); }
.setup-panel form { display: grid; gap: 12px; }
.setup-panel label { display: grid; gap: 6px; font-size: .875rem; }
.setup-panel input {
  min-width: 0;
  width: 100%;
  padding: 10px 11px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.setup-panel input::placeholder { color: var(--muted); }
.setup-panel input:focus-visible { background: var(--focus); }
.form-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-button, .secondary-button {
  min-height: 42px;
  padding: 8px 12px;
  background: var(--control);
  font-weight: 700;
  font-size: .875rem;
}
.action-button { background: #365f32; }
.action-button:hover, .action-button:focus-visible { background: #42733c; }
.setup-panel button:disabled { cursor: wait; opacity: .65; }
#join-form { margin-top: 22px; }
#setup-status { margin-top: 10px; }
.setup-panel .check-option { display: flex; align-items: center; gap: 9px; color: var(--muted); cursor: pointer; }
.setup-panel .check-option input {
  appearance: none;
  display: grid;
  place-content: center;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  cursor: pointer;
}
.check-option input:checked::after { content: "✓"; color: var(--text); }
.check-option input:checked { background: #365f32; }
.check-option input:checked:focus-visible { background: var(--focus); }
.menu-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.menu-tools button { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-options { margin: 0 0 16px; }
.auth-options [aria-pressed="true"] { background: #365f32; }
.auth-options [aria-pressed="true"]:focus-visible { background: #42733c; }
.account-note { color: var(--muted); }
.account-name { margin: 0 0 12px; font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
#account-status { margin-top: 12px; }
.history-shell { align-items: start; }
.history-panel { width: min(100%, 540px); }
.round-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.round-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  min-height: 65px;
  padding: 10px 13px;
  background: var(--control);
}
.round-list li:nth-child(even) { background: #28282a; }
.round-player, .round-summary { display: grid; gap: 4px; min-width: 0; }
.round-player strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.round-player small, .round-summary time { color: var(--muted); font-size: .75rem; }
.round-summary { flex: 0 0 auto; text-align: right; }
.round-result { font-weight: 700; font-size: .8125rem; }
.round-result[data-won="true"] { color: #a6cd9f; }
#more-rounds { width: 100%; margin-top: 12px; }

.party {
  position: fixed;
  z-index: 2;
  top: 24px;
  left: 24px;
  width: 144px;
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card { width: 100%; background: var(--panel); }
.invite, .player { display: flex; align-items: center; gap: 8px; padding: 9px; }
.invite { min-height: 50px; text-align: left; font-weight: 750; font-size: .8125rem; }
.invite:hover, .help:hover, .result button:hover { background: var(--hover); }
.invite:focus-visible, .help:focus-visible, .result button:focus-visible { background: var(--focus); }
.invite-icon, .avatar {
  flex: 0 0 30px;
  height: 30px;
  display: grid;
  place-items: center;
}
.invite-icon { background: var(--correct); }
.avatar { background: var(--avatar, #464647); font-weight: 700; font-size: .875rem; }
.invite-toast { font-size: .8125rem; }
.invite-toast:empty { display: none; }
.players { display: grid; gap: 8px; padding: 0; overflow: auto; scrollbar-width: thin; }
.player { justify-content: space-between; padding-inline: 12px; }
.mini-board { --mini: 6px; display: grid; grid-template-columns: repeat(var(--columns), var(--mini)); grid-template-rows: repeat(var(--rows), var(--mini)); gap: 2px; }
.mini-tile { background: #353538; }

.stage { min-height: 100dvh; display: grid; place-items: center; }
.game {
  --gap: 6px;
  --vertical-space: 152px;
  --horizontal-space: 36px;
  --tile: clamp(14px, min(
    calc((100vw - var(--horizontal-space) - (var(--columns) - 1) * var(--gap)) / var(--columns)),
    calc((100dvh - var(--vertical-space) - (var(--rows) - 1) * var(--gap)) / var(--rows))
  ), 60px);
  position: relative;
}
.board { display: grid; gap: var(--gap); width: max-content; touch-action: manipulation; }
.row { display: grid; grid-template-columns: repeat(var(--columns), var(--tile)); gap: var(--gap); }
.tile {
  display: grid;
  place-items: center;
  width: var(--tile);
  aspect-ratio: 1;
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
  font-size: min(2rem, calc(var(--tile) * .55));
  line-height: 1;
  user-select: none;
}
.board:focus-visible .tile:not([data-mark]) { background: #29292b; }
.board .tile.filled:not([data-mark]) { background: var(--hover); }
.tile[data-mark="exact"], .sample[data-mark="exact"], .mini-tile[data-mark="exact"] { --mark: var(--correct); }
.tile[data-mark="near"], .sample[data-mark="near"], .mini-tile[data-mark="near"] { --mark: var(--present); }
.tile[data-mark="miss"], .sample[data-mark="miss"], .mini-tile[data-mark="miss"] { --mark: var(--absent); }
[data-mark] { background: var(--mark); }
.tile.pop { animation: pop 135ms ease-out; }
.revealing .tile { animation: flip 440ms ease both; animation-delay: calc(var(--index) * 95ms); }
@keyframes pop {
  0% { transform: scale(.89); }
  65% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes flip {
  0% { transform: rotateX(0); background: var(--hover); }
  49% { background: var(--hover); }
  50% { transform: rotateX(-90deg); background: var(--mark); }
  100% { transform: rotateX(0); }
}
.mobile-input {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  pointer-events: none;
}
.feedback {
  position: absolute;
  top: calc(100% + 12px);
  width: 100%;
  text-align: center;
}
.status { margin: 0; color: #d1d1d3; font-size: .875rem; }
.status:empty { display: none; }
.status[data-tone="error"] { color: #ffd1ce; }
.result { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.result button, .close {
  padding: 5px 9px;
  background: var(--control);
  font-size: .8125rem;
}
.share-text { width: 100%; resize: vertical; padding: 5px; background: var(--field); }
.share-text:focus-visible { background: var(--focus); }

dialog {
  width: min(420px, calc(100% - 32px));
  padding: 22px;
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 28px 0 0; }
dialog p { line-height: 1.5; }
dialog a { color: var(--muted); }
.close { position: absolute; top: 14px; right: 14px; font-size: 1.1rem; }
.legend { display: grid; gap: 8px; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 10px; }
.sample { display: grid; place-items: center; width: 30px; height: 30px; font-weight: 800; }

@media (min-width: 636px) {
  body:has(.party:not([hidden])) .game { --horizontal-space: 352px; }
}
@media (max-width: 635px) {
  .game { --gap: 4px; --vertical-space: 180px; }
  body:not(.typing):has(.player) .game { --vertical-space: 280px; }
  .party { top: 12px; left: 12px; bottom: auto; width: 129px; max-height: none; }
  .invite { min-height: 38px; gap: 6px; padding: 5px 7px; font-size: .75rem; }
  .invite-icon, .avatar { flex-basis: 25px; height: 25px; }
  .masthead { top: 12px; right: 103px; left: auto; align-items: start; justify-items: end; gap: 3px; transform: none; }
  .masthead strong { font-size: 1.1rem; }
  .masthead span { font-size: .75rem; }
  .help { top: 12px; right: 12px; width: 29px; height: 29px; }
  .home { top: 12px; right: 48px; height: 29px; padding-inline: 7px; }
  .party:has(.player) { width: calc(100vw - 24px); }
  .party:has(.player) .invite { width: 129px; }
  .players { display: flex; margin-top: 20px; overflow-x: auto; }
  .player { width: auto; flex: 0 0 auto; gap: 5px; padding: 4px 6px; }
  .mini-board { --mini: 4px; gap: 1px; }
  .invite-toast { position: absolute; top: 39px; left: 0; }
}
@media (max-height: 450px) {
  .game { --gap: 3px; --vertical-space: 120px; }
  .masthead { top: 8px; gap: 4px; }
  .feedback { top: calc(100% + 5px); }
  .party { max-height: calc(100dvh - 24px); }
}
@media (max-width: 635px) and (max-height: 500px) {
  body.typing .players { visibility: hidden; }
}
@media (max-width: 390px) {
  body:has(.party:not([hidden])) .masthead strong { display: none; }
  body:has(.party:not([hidden])) .masthead span { margin-top: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile.pop, .revealing .tile { animation: none; }
}
