:root {
  color-scheme: dark;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  background: #111319;
  color: #f4f3ee;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --green: #a9df78;
  --yellow: #e8c66c;
  --gray: #555b68;
  --line: #383d49;
  --muted: #9298a5;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  background:
    radial-gradient(ellipse at 50% -18%, #34344e 0, transparent 48%),
    radial-gradient(ellipse at 2% 100%, #192526 0, transparent 35%),
    #111319;
}

button {
  font: inherit;
}

.game {
  width: min(100% - 32px, 490px);
  min-height: calc(100vh - 48px);
  min-height: calc(100svh - 48px);
  margin: 24px auto;
  padding: 0 23px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid #ffffff12;
  border-radius: 25px;
  background: linear-gradient(155deg, #1c1f29ed, #191c24f2 65%, #171d20f2);
  box-shadow: 0 28px 80px #0006, inset 0 1px #ffffff0b;
}

.play-layout {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.controls-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.controls-heading,
.controls-note {
  display: none;
}

.topbar {
  width: 100%;
  min-height: 70px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  border-bottom: 1px solid #ffffff12;
}

.topbar-actions {
  display: flex;
  gap: 7px;
}

.topbar h1 {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  text-align: left;
}

.brand-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #171b19;
  background: var(--green);
  font-size: 19px;
  font-weight: 900;
  letter-spacing: -1px;
  transform: rotate(-5deg);
}

.brand-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 17px;
  font-weight: 850;
  letter-spacing: 2.6px;
}

.brand-name small {
  color: var(--muted);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 3px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #ffffff18;
  border-radius: 12px;
  color: #d4d5da;
  background: #ffffff06;
  cursor: pointer;
  font-size: 19px;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: #a9df7870;
  color: var(--green);
  background: #a9df7812;
}

#new-game-button:hover {
  transform: rotate(-35deg);
}

.intro {
  margin: 19px 0 16px;
  text-align: center;
}

.eyebrow {
  color: var(--green);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2.6px;
}

.intro h2 {
  margin: 5px 0 3px;
  font-size: clamp(20px, 5vw, 24px);
  font-weight: 750;
  letter-spacing: -.6px;
}

.subtle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.player-summary {
  min-height: 15px;
  margin: 4px 0 0;
  color: var(--green);
  font-size: 11px;
  font-weight: 650;
}

.profile-status {
  margin: 0;
  color: #ffb3a8;
  font-size: 10px !important;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 7px;
  width: min(100%, 340px);
  aspect-ratio: 5 / 6;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.tile {
  display: grid;
  place-items: center;
  border: 1px solid #3b404c;
  border-radius: 10px;
  background: #ffffff04;
  color: #fbfaf5;
  font-size: clamp(24px, 8vw, 34px);
  font-weight: 800;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  transition: border-color 120ms ease, background 180ms ease;
}

.tile.filled {
  border-color: #797d8b;
  background: #ffffff0a;
  animation: pop 130ms ease-in-out;
}

.tile.reveal {
  animation: flip 420ms ease-in-out both;
}

.tile.correct,
.key.correct,
.example-tile.correct {
  color: #182018;
  background: var(--green);
  border-color: var(--green);
}

.tile.present,
.key.present,
.example-tile.present {
  color: #242016;
  background: var(--yellow);
  border-color: var(--yellow);
}

.tile.absent,
.key.absent {
  color: #fff;
  background: var(--gray);
  border-color: var(--gray);
}

.message {
  min-height: 28px;
  margin: 9px 0 2px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.message:empty {
  min-height: 12px;
}

.keyboard {
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 17px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  min-width: 0;
  height: 48px;
  flex: 1;
  padding: 0;
  border: 1px solid #ffffff08;
  border-radius: 8px;
  background: #353a46;
  color: #f0f0ed;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  touch-action: manipulation;
  transition: filter 130ms ease, transform 100ms ease, background 160ms ease;
}

[data-input="touch"] .key {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.key.wide {
  flex: 1.55;
  font-size: 10px;
  letter-spacing: .5px;
}

.key:not(.correct, .present, .absent):hover {
  background: #454b59;
}

.key:active {
  transform: scale(.95);
}

footer {
  margin-top: auto;
  padding: 9px 0 0;
  color: #777e8b;
  font-size: 11px;
  text-align: center;
}

footer button {
  border: 0;
  padding: 0;
  color: var(--green);
  background: none;
  cursor: pointer;
  font-weight: 700;
}

footer button:hover {
  color: #d0f3ab;
  text-decoration: underline;
}

dialog {
  width: min(440px, calc(100% - 32px));
  border: 1px solid #ffffff1c;
  border-radius: 18px;
  padding: 27px;
  color: #f4f3ee;
  background: #20232d;
  box-shadow: 0 20px 70px #0009;
  line-height: 1.55;
}

dialog::backdrop {
  background: #08090dbd;
  backdrop-filter: blur(5px);
}

dialog h2 {
  margin: 0 0 12px;
}

dialog p {
  color: #c2c5cd;
  font-size: 14px;
}

dialog strong {
  color: #fff;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 16px;
  border: 0;
  color: #bfc3cd;
  background: none;
  cursor: pointer;
  font-size: 26px;
}

.primary-button,
.secondary-button {
  min-height: 38px;
  border: 1px solid #ffffff20;
  border-radius: 10px;
  padding: 0 13px;
  color: #eff0e9;
  background: #ffffff08;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.primary-button {
  border-color: #a9df7870;
  color: #182016;
  background: var(--green);
}

.primary-button:hover {
  background: #c4efa0;
}

.secondary-button:hover {
  border-color: #a9df7870;
  color: var(--green);
}

#nickname-form label {
  display: block;
  margin-top: 18px;
  color: #f4f3ee;
  font-size: 12px;
  font-weight: 700;
}

#nickname-input {
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  border: 1px solid #ffffff25;
  border-radius: 10px;
  padding: 0 12px;
  color: #fff;
  background: #111319;
  font: inherit;
}

#nickname-input:focus {
  border-color: var(--green);
  outline: 2px solid #a9df7833;
}

.dialog-hint,
.privacy-note {
  margin: 7px 0;
  font-size: 11px !important;
}

.dialog-error {
  min-height: 20px;
  margin: 5px 0;
  color: #ff9898 !important;
  font-size: 12px !important;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.leaderboard-dialog {
  width: min(980px, calc(100% - 32px));
  padding: clamp(20px, 4vw, 34px);
}

.leaderboard-header,
.leaderboard-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.leaderboard-header h2 {
  margin: 3px 0 0;
  font-size: 26px;
}

.leaderboard-header p,
.leaderboard-footer p {
  margin: 5px 0 0;
  font-size: 12px;
}

.leaderboard-status {
  min-height: 17px;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 12px !important;
}

.leaderboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.leaderboard-card {
  min-width: 0;
  border: 1px solid #ffffff12;
  border-radius: 14px;
  padding: 14px;
  background: #ffffff05;
}

.rank-icon {
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
}

.leaderboard-card h3 {
  margin: 6px 0 3px;
  font-size: 15px;
}

.leaderboard-card > p {
  min-height: 34px;
  margin: 0 0 12px;
  font-size: 11px;
  line-height: 1.4;
}

.leaderboard-entries {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-entries li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  border-top: 1px solid #ffffff0d;
  padding-top: 7px;
  font-size: 11px;
}

.leaderboard-entries .place {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.leaderboard-entries .player-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-entries .player-score {
  color: var(--green);
  font-weight: 700;
  white-space: nowrap;
}

.leaderboard-empty {
  color: var(--muted);
  font-size: 11px;
}

.leaderboard-footer {
  margin-top: 16px;
  border-top: 1px solid #ffffff12;
  padding-top: 12px;
}

.leaderboard-footer p {
  margin: 0;
}

dialog {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.example {
  display: flex;
  gap: 5px;
  margin: 12px 0 4px;
}

.example-tile {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #464b58;
  border-radius: 7px;
  font-weight: 800;
}

kbd {
  border: 1px solid #4a4f5b;
  border-radius: 5px;
  padding: 2px 5px;
  color: #f4f3ee;
  background: #292d37;
}

@keyframes pop {
  50% { transform: scale(1.08); }
}

@keyframes flip {
  0%, 100% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
}

@media (max-width: 699px) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .game {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background:
      radial-gradient(ellipse at 50% -18%, #34344e 0, transparent 48%),
      #171a22;
    box-shadow: none;
  }

  .topbar {
    flex: 0 0 56px;
    min-height: 56px;
    grid-template-columns: 36px minmax(0, 1fr) auto;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-actions .icon-button {
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .intro {
    flex: 0 0 auto;
    margin: 10px 0 12px;
  }

  .play-layout {
    flex: 1 1 0;
    min-height: 0;
    align-items: stretch;
    justify-content: flex-start;
    gap: 5px;
  }

  .board-panel {
    flex: 1 1 auto;
    min-height: 0;
    justify-content: center;
  }

  .controls-panel {
    flex: 0 0 auto;
  }

  .controls-heading,
  .controls-note {
    display: none;
  }

  .board {
    width: min(100%, 42dvh, calc(83.333dvh - 283.333px), 340px);
    max-height: calc(100% - 24px);
  }

  .keyboard {
    width: min(100%, 440px);
    flex: 0 0 auto;
    gap: clamp(4px, .8dvh, 7px);
    margin: 3px 0 5px;
  }

  .key {
    height: clamp(36px, 7.2dvh, 50px);
  }

  footer {
    display: none;
  }

  dialog {
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
  }

  dialog[open] {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .keyboard-row {
    gap: 4px;
  }

  .player-summary {
    margin-top: 2px;
    font-size: 10px;
  }

  .leaderboard-grid {
    grid-template-columns: 1fr;
  }

  .leaderboard-card > p {
    min-height: 0;
  }

  .leaderboard-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .leaderboard-dialog {
    padding: 22px 16px;
  }

  .leaderboard-header h2 {
    font-size: 22px;
  }
}

@media (max-width: 380px) {
  .game {
    padding-right: max(10px, env(safe-area-inset-right));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .keyboard-row {
    gap: 3px;
  }

  .brand-name {
    font-size: 14px;
    letter-spacing: 2px;
  }

  .brand-name small {
    letter-spacing: 2px;
  }

  .key {
    border-radius: 6px;
    font-size: 12px;
  }

  .key.wide {
    font-size: 9px;
  }
}

@media (max-width: 699px) and (max-height: 780px) {
  .topbar {
    flex-basis: 52px;
    min-height: 52px;
  }

  .intro {
    margin: 6px 0 8px;
  }

  .board {
    width: min(100%, 44dvh, calc(83.333dvh - 283.333px), 340px);
  }

  .key {
    height: clamp(34px, 6.8dvh, 44px);
    border-radius: 7px;
  }

  .keyboard {
    gap: clamp(4px, .8dvh, 6px);
    margin: 2px 0 4px;
  }
}

@media (max-width: 699px) and (max-height: 600px) and (orientation: portrait) {
  .topbar {
    flex-basis: 46px;
    min-height: 46px;
  }

  .intro {
    margin: 4px 0 5px;
  }

  .eyebrow,
  .subtle {
    display: none;
  }

  .intro h2 {
    margin: 0;
    font-size: clamp(18px, 5vw, 21px);
  }

  .board {
    width: min(100%, 42dvh, calc(83.333dvh - 208.333px), 340px);
  }

  .key {
    height: clamp(34px, 7.2dvh, 42px);
  }

  .keyboard {
    margin: 2px 0 3px;
  }
}

@media (min-width: 700px) and (max-width: 899px) {
  .game {
    width: min(100% - 40px, 820px);
  }

  .board {
    width: min(100%, 390px);
  }
}

@media (min-width: 900px) {
  html,
  body {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    height: 100vh;
    height: 100svh;
  }

  .game {
    width: min(calc(100% - 64px), 1180px);
    height: min(820px, calc(100svh - 48px));
    min-height: 0;
    padding: 0 clamp(34px, 6vw, 76px) 22px;
  }

  .topbar {
    min-height: 74px;
  }

  .intro {
    margin: 21px 0 15px;
  }

  .intro h2 {
    font-size: 29px;
  }

  .play-layout {
    width: min(100%, 940px);
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, .92fr);
    align-items: center;
    gap: clamp(42px, 6vw, 82px);
    margin: auto 0 16px;
  }

  .board-panel {
    width: 100%;
  }

  .board {
    width: min(100%, 420px);
    gap: 10px;
  }

  .board-row {
    gap: 10px;
  }

  .tile {
    border-radius: 14px;
    font-size: clamp(30px, 3vw, 42px);
  }

  .controls-panel {
    width: 100%;
    min-width: 0;
    padding: clamp(22px, 2.3vw, 30px);
    border: 1px solid #ffffff12;
    border-radius: 24px;
    background: linear-gradient(145deg, #232733, #1d2029);
    box-shadow: inset 0 1px #ffffff08, 0 20px 45px #0002;
  }

  .controls-heading {
    width: 100%;
    display: block;
    margin-bottom: 22px;
  }

  .controls-heading h3 {
    margin: 8px 0 5px;
    font-size: 25px;
    letter-spacing: -.4px;
  }

  .controls-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
  }

  .keyboard {
    width: 100%;
    gap: 10px;
    margin: 0;
  }

  .keyboard-row {
    gap: 5px;
  }

  .key {
    height: clamp(48px, 6svh, 60px);
    border-radius: 9px;
    font-size: 15px;
  }

  .key.wide {
    font-size: 11px;
  }

  .controls-note {
    width: 100%;
    display: block;
    margin: 20px 0 0;
    padding-top: 15px;
    border-top: 1px solid #ffffff12;
    color: var(--muted);
    font-size: 12px;
    line-height: 2;
    text-align: center;
  }

  .controls-note kbd {
    margin: 0 3px;
  }
}

@media (min-width: 900px) and (max-height: 760px) {
  .game {
    height: calc(100svh - 24px);
    min-height: 0;
    margin-top: 12px;
    margin-bottom: 12px;
  }

  .topbar {
    min-height: 60px;
  }

  .intro {
    margin: 11px 0 9px;
  }

  .play-layout {
    margin-bottom: 8px;
  }

  .board {
    width: min(100%, 36svh, 380px);
  }

  .tile {
    border-radius: 10px;
  }

  .controls-panel {
    padding: 20px;
  }

  .controls-heading {
    margin-bottom: 15px;
  }

  .controls-heading h3 {
    margin-top: 5px;
    font-size: 22px;
  }

  .controls-note {
    margin-top: 14px;
    padding-top: 10px;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .game {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    padding: env(safe-area-inset-top) max(18px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(18px, env(safe-area-inset-left));
    overflow: hidden;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .topbar {
    flex: 0 0 44px;
    min-height: 44px;
  }

  .intro {
    flex: 0 0 auto;
    margin: 3px 0 5px;
  }

  .eyebrow,
  .subtle {
    display: none;
  }

  .intro h2 {
    margin: 0;
    font-size: 18px;
  }

  .play-layout {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(12px, 3vw, 32px);
    margin: 0;
  }

  .board-panel {
    width: auto;
    flex: 0 1 auto;
    min-height: 0;
  }

  .board {
    width: min(52dvh, calc(83.333dvh - 125px), 240px);
    max-height: calc(100% - 23px);
    gap: 5px;
  }

  .board-row {
    gap: 5px;
  }

  .tile {
    border-radius: 7px;
    font-size: clamp(20px, 5dvh, 27px);
  }

  .message {
    min-height: 18px;
    margin: 2px 0 0;
    font-size: 11px;
  }

  .message:empty {
    min-height: 12px;
  }

  .controls-panel {
    width: min(52vw, 400px);
    flex: 0 1 400px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
  }

  .controls-heading,
  .controls-note {
    display: none;
  }

  .keyboard {
    width: 100%;
    gap: 4px;
    margin: 0;
  }

  .keyboard-row {
    gap: 3px;
  }

  .key {
    height: clamp(30px, 8dvh, 42px);
    border-radius: 6px;
    font-size: 11px;
  }

  .key.wide {
    font-size: 8px;
  }

  footer {
    display: none;
  }
}

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