:root {
  color-scheme: light;
  --canvas: #edf2f3;
  --surface: #ffffff;
  --surface-muted: #dfe8e9;
  --ink: #17353b;
  --ink-soft: #52676c;
  --line: #b6c5c8;
  --line-strong: #768b90;
  --correct: #197653;
  --correct-ink: #ffffff;
  --present: #e2ad39;
  --present-ink: #1e2d30;
  --absent: #637479;
  --absent-ink: #ffffff;
  --danger: #a43b36;
  --focus: #156b92;
  --tile-size: 3.45rem;
  --radius: 0.75rem;
  --topbar-height: 4rem;
  --z-sticky: 20;
  --z-popover: 40;
  --z-dialog: 80;
  --z-toast: 100;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
  background: var(--canvas);
}

body {
  margin: 0;
  min-width: 20rem;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--canvas);
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Noto Sans TC",
    "Noto Sans",
    sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

button,
select,
input {
  font: inherit;
}

button,
summary,
select,
input {
  touch-action: manipulation;
}

button,
summary {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

[hidden] {
  display: none !important;
}

svg {
  display: block;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  inset-block-start: 0.5rem;
  inset-inline-start: 0.5rem;
  z-index: var(--z-toast);
  padding: 0.7rem 1rem;
  border-radius: 0.5rem;
  background: var(--ink);
  color: #ffffff;
  font-weight: 750;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: var(--z-sticky);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  min-height: var(--topbar-height);
  padding-inline: max(1rem, calc((100vw - 70rem) / 2));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.back-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  gap: 0.4rem;
  padding: 0.45rem 0.65rem;
  border-radius: 0.5rem;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 720;
  text-decoration: none;
  transition:
    background-color 180ms ease,
    color 180ms ease;
}

.back-link:hover {
  background: var(--surface-muted);
}

.back-link svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;
  border-radius: 0.35rem;
  background: var(--correct);
  color: var(--correct-ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 850;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.brand-lockup h1,
.brand-lockup span {
  margin: 0;
}

.brand-lockup h1 {
  font-size: 1.05rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  line-height: 1.1;
}

.brand-label {
  display: block;
  margin-block-end: 0.12rem !important;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

.top-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.icon-button {
  display: inline-flex;
  min-width: 2.75rem;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.65rem;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  transition:
    background-color 180ms ease,
    transform 120ms ease;
}

.icon-button::-webkit-details-marker {
  display: none;
}

.icon-button:hover {
  background: var(--surface-muted);
}

.icon-button:active {
  transform: translateY(1px);
}

.icon-button svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.action-label {
  font-size: 0.78rem;
  font-weight: 720;
}

.settings {
  position: relative;
}

.settings[open] > summary {
  background: var(--ink);
  color: #ffffff;
}

.settings-panel {
  position: absolute;
  inset-block-start: calc(100% + 0.5rem);
  inset-inline-end: 0;
  z-index: var(--z-popover);
  width: min(19rem, calc(100vw - 1.5rem));
  padding: 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 6px 8px rgba(23, 53, 59, 0.16);
}

.settings-panel > label:first-child {
  display: block;
  margin-block-end: 0.4rem;
  color: var(--ink-soft);
  font-size: 0.76rem;
  font-weight: 750;
}

.settings-panel select {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.55rem 2.3rem 0.55rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--ink);
}

.sound-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-block-start: 0.9rem;
  padding-block: 0.85rem;
  border-block: 1px solid var(--line);
  cursor: pointer;
}

.sound-setting span,
.sound-setting strong,
.sound-setting small {
  display: block;
}

.sound-setting strong {
  font-size: 0.88rem;
}

.sound-setting small {
  max-width: 17rem;
  margin-block-start: 0.15rem;
  color: var(--ink-soft);
  font-size: 0.72rem;
  line-height: 1.35;
}

.sound-setting input {
  width: 2.6rem;
  height: 1.45rem;
  flex: 0 0 auto;
  accent-color: var(--correct);
  cursor: pointer;
}

.version-row {
  display: flex;
  justify-content: space-between;
  padding-block-start: 0.8rem;
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.game-main {
  display: grid;
  grid-template-columns: minmax(20rem, 0.88fr) minmax(24rem, 1.12fr);
  width: min(62rem, calc(100% - 2rem));
  min-height: min(43rem, calc(100dvh - var(--topbar-height) - 2.5rem));
  margin: 1.25rem auto;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 4px 8px rgba(23, 53, 59, 0.14);
}

.puzzle-stage {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  padding: 2rem 2.2rem 1.6rem;
  background: var(--surface);
}

.stage-heading {
  display: flex;
  width: 100%;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-block-end: 0.75rem;
}

.daily-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.3rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 720;
}

.daily-label time::before {
  content: "·";
  margin-inline-end: 0.5rem;
}

.stage-heading h2 {
  max-width: 28rem;
  margin: 0;
  font-size: 1.02rem;
  font-weight: 720;
  letter-spacing: -0.015em;
  line-height: 1.35;
  text-wrap: pretty;
}

.attempt-copy {
  flex: 0 0 auto;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 760;
}

.attempt-meter {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  width: 100%;
  gap: 0.3rem;
  margin-block-end: 1rem;
}

.attempt-segment {
  height: 0.22rem;
  border-radius: 999px;
  background: var(--surface-muted);
  transition: background-color 180ms ease;
}

.attempt-segment.completed {
  background: var(--line-strong);
}

.attempt-segment.current {
  background: var(--correct);
}

.board {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: fit-content;
  max-width: 100%;
  direction: ltr;
}

.board-row {
  display: grid;
  grid-template-columns: 1.25rem repeat(5, var(--tile-size));
  align-items: center;
  gap: 0.35rem;
}

.row-number {
  color: var(--line-strong);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
  text-align: end;
  transition: color 180ms ease;
}

.board-row.current .row-number {
  color: var(--correct);
  font-weight: 800;
}

.tile {
  display: grid;
  width: var(--tile-size);
  height: var(--tile-size);
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 0.38rem;
  background: var(--surface);
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: calc(var(--tile-size) * 0.47);
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
  transform-origin: center;
  transition:
    border-color 150ms ease,
    background-color 180ms ease,
    color 180ms ease;
}

.tile.filled {
  border-color: var(--ink);
  animation: tile-pop 150ms cubic-bezier(0.22, 1, 0.36, 1);
}

.tile.correct {
  border-color: var(--correct);
  background: var(--correct);
  color: var(--correct-ink);
}

.tile.present {
  border-color: var(--present);
  background: var(--present);
  color: var(--present-ink);
}

.tile.absent {
  border-color: var(--absent);
  background: var(--absent);
  color: var(--absent-ink);
}

.tile.reveal {
  animation: tile-reveal 520ms cubic-bezier(0.22, 1, 0.36, 1);
  animation-delay: var(--reveal-delay, 0ms);
}

.board-row.invalid {
  animation: row-shake 360ms ease-out;
}

.result-panel {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-block-start: 1.1rem;
  padding-block-start: 1rem;
  border-top: 1px solid var(--line);
}

.result-panel h2,
.result-panel p {
  margin: 0;
}

.result-panel h2 {
  font-size: 1rem;
  font-weight: 800;
}

.result-panel p {
  max-width: 28rem;
  margin-block-start: 0.2rem;
  color: var(--ink-soft);
  font-size: 0.78rem;
  text-wrap: pretty;
}

.share-button {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--correct);
  color: var(--correct-ink);
  font-size: 0.8rem;
  font-weight: 780;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
  transition:
    filter 160ms ease,
    transform 120ms ease;
}

.share-button:hover {
  filter: brightness(1.06);
}

.share-button:active {
  transform: translateY(1px);
}

.share-button:disabled {
  background: var(--line-strong);
  cursor: not-allowed;
  filter: none;
}

.share-button svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.tool-deck {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.6rem;
  padding: 2rem 2.2rem;
  background: var(--surface-muted);
}

.clue-legend h2 {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  font-weight: 820;
}

.clue-legend ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.clue-legend li {
  display: flex;
  min-width: 9.5rem;
  flex: 1 1 9.5rem;
  align-items: center;
  gap: 0.65rem;
}

.legend-swatch {
  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 0.35rem;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 850;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}

.legend-swatch.correct {
  background: var(--correct);
  color: var(--correct-ink);
}

.legend-swatch.present {
  background: var(--present);
  color: var(--present-ink);
}

.legend-swatch.absent {
  background: var(--absent);
  color: var(--absent-ink);
}

.clue-legend strong,
.clue-legend small {
  display: block;
}

.clue-legend strong {
  font-size: 0.78rem;
}

.clue-legend small {
  max-width: 15rem;
  margin-block-start: 0.12rem;
  color: var(--ink-soft);
  font-size: 0.68rem;
  line-height: 1.32;
}

.keyboard-wrap {
  width: 100%;
}

.keyboard {
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: 0.42rem;
  direction: ltr;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 0.34rem;
}

.key {
  min-width: 0;
  min-height: 3rem;
  flex: 1 1 0;
  padding: 0.35rem 0.1rem 0.48rem;
  border: 0;
  border-radius: 0.42rem;
  background: #f8fafb;
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.72rem, 1.8vw, 0.92rem);
  font-weight: 820;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 #aababc;
  transition:
    background-color 150ms ease,
    color 150ms ease,
    transform 100ms ease;
}

.key:hover {
  background: #ffffff;
}

.key:active,
.key.pressed {
  transform: translateY(2px);
  box-shadow: inset 0 -1px 0 #aababc;
}

.key.wide {
  flex: 1.55 1 0;
  font-family: inherit;
  font-size: 0.68rem;
}

.key.correct {
  background: var(--correct);
  color: var(--correct-ink);
  box-shadow: inset 0 -3px 0 #0e5339;
}

.key.present {
  background: var(--present);
  color: var(--present-ink);
  box-shadow: inset 0 -3px 0 #aa7512;
}

.key.absent {
  background: var(--absent);
  color: var(--absent-ink);
  box-shadow: inset 0 -3px 0 #435258;
}

.stats-dialog {
  width: min(31rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 12px rgba(11, 34, 39, 0.28);
}

.stats-dialog::backdrop {
  background: rgba(10, 29, 34, 0.68);
}

.stats-dialog form {
  padding: 1.35rem;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block-end: 1rem;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 820;
}

.dialog-close {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 0;
  border-radius: 0.5rem;
  background: var(--surface-muted);
  color: var(--ink);
  cursor: pointer;
}

.dialog-close:hover {
  background: var(--line);
}

.dialog-close svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin: 1.2rem 0;
}

.stats-grid > div {
  min-width: 0;
  padding-inline: 0.55rem;
  text-align: center;
}

.stats-grid > div + div {
  border-inline-start: 1px solid var(--line);
}

.stats-grid dd,
.stats-grid dt {
  margin: 0;
}

.stats-grid dd {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 1.6rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.stats-grid dt {
  margin-block-start: 0.25rem;
  color: var(--ink-soft);
  font-size: 0.65rem;
  line-height: 1.25;
}

.distribution {
  padding-block: 0.5rem 1.1rem;
}

.distribution h3 {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  font-weight: 800;
}

.guess-bar {
  display: grid;
  grid-template-columns: 1.2rem 1fr;
  align-items: center;
  gap: 0.45rem;
  margin-block: 0.28rem;
}

.guess-number {
  color: var(--ink-soft);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 750;
}

.bar-track {
  height: 1.35rem;
  background: var(--surface-muted);
}

.bar-fill {
  display: flex;
  width: var(--bar-width, 7%);
  min-width: 1.65rem;
  height: 100%;
  align-items: center;
  justify-content: flex-end;
  padding-inline-end: 0.4rem;
  background: var(--absent);
  color: var(--absent-ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 800;
}

.bar-fill.current {
  background: var(--correct);
}

.dialog-share {
  width: 100%;
}

.toast {
  position: fixed;
  inset-block-start: calc(var(--topbar-height) + 0.75rem);
  inset-inline-start: 50%;
  z-index: var(--z-toast);
  max-width: min(28rem, calc(100vw - 2rem));
  margin: 0;
  padding: 0.7rem 0.9rem;
  border-radius: 0.5rem;
  background: var(--ink);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 720;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -0.5rem);
  transition:
    opacity 160ms ease,
    transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#fa-help-btn {
  inset-inline-end: 0.75rem !important;
  inset-block-end: 0.75rem !important;
  width: 2.75rem !important;
  height: 2.75rem !important;
}

html[dir="rtl"] .daily-label,
html[dir="rtl"] .stage-heading h2,
html[dir="rtl"] .clue-legend,
html[dir="rtl"] .settings-panel {
  text-align: start;
}

html[dir="rtl"] .settings-panel select {
  padding-inline: 2.3rem 0.7rem;
}

@keyframes tile-pop {
  0%,
  100% {
    transform: scale(1);
  }
  55% {
    transform: scale(1.08);
  }
}

@keyframes tile-reveal {
  0% {
    transform: rotateX(0);
  }
  48% {
    transform: rotateX(88deg);
  }
  100% {
    transform: rotateX(0);
  }
}

@keyframes row-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-0.35rem);
  }
  50% {
    transform: translateX(0.35rem);
  }
  75% {
    transform: translateX(-0.2rem);
  }
}

@media (max-width: 52rem) {
  :root {
    --tile-size: 3.2rem;
  }

  .action-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .game-main {
    grid-template-columns: minmax(18.5rem, 0.9fr) minmax(20rem, 1.1fr);
    width: calc(100% - 1rem);
    margin-block: 0.5rem;
  }

  .puzzle-stage,
  .tool-deck {
    padding: 1.35rem;
  }

  .clue-legend li {
    min-width: 7.5rem;
    flex-basis: 7.5rem;
  }
}

@media (max-width: 43rem) {
  :root {
    --tile-size: clamp(2.75rem, 13.4vw, 3.25rem);
  }

  .topbar {
    padding-inline: 0.65rem;
  }

  .brand-label {
    display: none;
  }

  .game-main {
    display: flex;
    width: min(27rem, 100%);
    min-height: calc(100dvh - var(--topbar-height));
    flex-direction: column;
    margin: 0 auto;
    overflow: visible;
    border-radius: 0;
    box-shadow: none;
  }

  .puzzle-stage {
    padding: 1rem 0.85rem 0.75rem;
  }

  .stage-heading {
    align-items: flex-start;
    margin-block-end: 0.55rem;
  }

  .daily-label {
    margin-block-end: 0.15rem;
  }

  .stage-heading h2 {
    font-size: 0.92rem;
  }

  .attempt-copy {
    padding-block-start: 0.15rem;
    font-size: 0.68rem;
  }

  .attempt-meter {
    margin-block-end: 0.65rem;
  }

  .board {
    gap: 0.25rem;
  }

  .board-row {
    grid-template-columns: 1rem repeat(5, var(--tile-size));
    gap: 0.25rem;
  }

  .result-panel {
    margin-block-start: 0.75rem;
    padding-block-start: 0.75rem;
  }

  .tool-deck {
    flex: 1 0 auto;
    gap: 0.8rem;
    padding: 0.75rem 0.45rem max(4rem, env(safe-area-inset-bottom));
  }

  .clue-legend {
    padding-inline: 0.4rem;
  }

  .clue-legend h2 {
    display: none;
  }

  .clue-legend ul {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0.5rem;
  }

  .clue-legend li {
    min-width: 0;
    flex: 0 1 auto;
    gap: 0.35rem;
  }

  .legend-swatch {
    width: 1.7rem;
    height: 1.7rem;
    font-size: 0.72rem;
  }

  .clue-legend strong {
    font-size: 0.65rem;
  }

  .clue-legend small {
    display: none;
  }

  .keyboard {
    gap: 0.36rem;
  }

  .keyboard-row {
    gap: 0.25rem;
  }

  .key {
    min-height: 2.9rem;
    border-radius: 0.35rem;
    font-size: 0.78rem;
  }

  .key.wide {
    font-size: 0.62rem;
  }

  #fa-help-btn {
    inset-block-end: 0.6rem !important;
    inset-inline-end: 0.6rem !important;
  }
}

@media (max-width: 23rem) {
  :root {
    --tile-size: clamp(2.45rem, 13.3vw, 2.9rem);
  }

  .back-link span {
    display: none;
  }

  .brand-mark {
    width: 2rem;
    height: 2rem;
  }

  .brand-lockup {
    gap: 0.4rem;
  }

  .brand-lockup h1 {
    font-size: 0.92rem;
  }

  .top-actions {
    gap: 0.05rem;
  }

  .icon-button {
    min-width: 2.55rem;
    min-height: 2.55rem;
    padding-inline: 0.45rem;
  }

  .stage-heading {
    display: block;
  }

  .attempt-copy {
    margin-block-start: 0.25rem;
  }

  .result-panel {
    align-items: flex-start;
  }
}

@media (min-width: 43.01rem) and (max-height: 36rem) {
  :root {
    --topbar-height: 3.5rem;
    --tile-size: clamp(2.7rem, 8vh, 3rem);
  }

  body {
    overflow-y: hidden;
  }

  .topbar {
    min-height: var(--topbar-height);
  }

  .game-main {
    width: min(62rem, calc(100% - 1.5rem));
    min-height: 0;
    height: calc(100dvh - var(--topbar-height) - 1.5rem);
    margin: 0.75rem auto;
  }

  .puzzle-stage,
  .tool-deck {
    padding: 1rem 1.25rem;
  }

  .stage-heading {
    margin-block-end: 0.4rem;
  }

  .attempt-meter {
    margin-block-end: 0.55rem;
  }

  .board {
    gap: 0.25rem;
  }

  .board-row {
    grid-template-columns: 1rem repeat(5, var(--tile-size));
    gap: 0.25rem;
  }

  .tool-deck {
    gap: 0.75rem;
  }

  .clue-legend h2 {
    margin-block-end: 0.5rem;
  }

  .clue-legend ul {
    gap: 0.4rem 0.8rem;
  }

  .clue-legend li {
    gap: 0.45rem;
  }

  .legend-swatch {
    width: 1.8rem;
    height: 1.8rem;
    font-size: 0.72rem;
  }

  .keyboard {
    gap: 0.25rem;
  }

  .keyboard-row {
    gap: 0.25rem;
  }

  .key {
    min-height: 2.35rem;
    padding-block: 0.25rem 0.38rem;
  }

  #fa-help-btn {
    inset: auto auto 0.55rem 0.55rem !important;
  }
}

@media (min-width: 32.5rem) and (max-height: 27rem) {
  :root {
    --topbar-height: 2.75rem;
    --tile-size: clamp(2rem, 9.8vh, 2.45rem);
  }

  body {
    overflow-y: hidden;
  }

  .topbar {
    min-height: var(--topbar-height);
    padding-inline: 0.5rem;
  }

  .back-link,
  .icon-button {
    min-height: 2.25rem;
  }

  .back-link span,
  .action-label,
  .brand-label {
    display: none;
  }

  .brand-mark {
    width: 1.9rem;
    height: 1.9rem;
    font-size: 0.95rem;
  }

  .brand-lockup h1 {
    font-size: 0.85rem;
  }

  .icon-button {
    min-width: 2.25rem;
    padding: 0.35rem;
  }

  .game-main {
    display: grid;
    grid-template-columns: minmax(14.5rem, 0.86fr) minmax(18rem, 1.14fr);
    width: 100%;
    max-width: none;
    min-height: calc(100dvh - var(--topbar-height));
    height: calc(100dvh - var(--topbar-height));
    margin: 0;
    overflow: hidden;
    border-radius: 0;
    box-shadow: none;
  }

  .puzzle-stage {
    justify-content: center;
    padding: 0.35rem 0.6rem;
  }

  .stage-heading {
    align-items: center;
    margin-block-end: 0.3rem;
  }

  .daily-label {
    margin: 0;
    font-size: 0.58rem;
  }

  .daily-label time,
  .stage-heading h2 {
    display: none;
  }

  .attempt-copy {
    font-size: 0.6rem;
  }

  .attempt-meter {
    margin-block-end: 0.35rem;
  }

  .board {
    gap: 0.2rem;
  }

  .board-row {
    grid-template-columns: 0.85rem repeat(5, var(--tile-size));
    gap: 0.22rem;
  }

  .row-number {
    font-size: 0.52rem;
  }

  .result-panel {
    position: absolute;
    inset-inline-start: 0.5rem;
    inset-block-end: 0.4rem;
    width: calc(43% - 1rem);
    margin: 0;
    padding: 0;
    border: 0;
  }

  .result-panel h2 {
    font-size: 0.72rem;
  }

  .result-panel p {
    display: none;
  }

  .result-panel .share-button {
    min-height: 2rem;
    padding: 0.3rem 0.5rem;
    font-size: 0.6rem;
  }

  .tool-deck {
    justify-content: center;
    gap: 0.6rem;
    padding: 0.45rem 0.55rem 0.6rem;
  }

  .clue-legend h2 {
    display: none;
  }

  .clue-legend ul {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0.45rem;
  }

  .clue-legend li {
    min-width: 0;
    flex: 0 1 auto;
    gap: 0.28rem;
  }

  .legend-swatch {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.62rem;
  }

  .clue-legend strong {
    font-size: 0.58rem;
  }

  .clue-legend small {
    display: none;
  }

  .keyboard {
    gap: 0.25rem;
  }

  .keyboard-row {
    gap: 0.22rem;
  }

  .key {
    min-height: clamp(2rem, 11.5vh, 2.55rem);
    padding: 0.2rem 0.05rem 0.35rem;
    font-size: 0.68rem;
  }

  .key.wide {
    font-size: 0.52rem;
  }

  .settings-panel {
    inset-block-start: calc(100% + 0.2rem);
    max-height: calc(100dvh - 3.2rem);
    overflow: auto;
  }

  #fa-help-btn {
    inset: 0.3rem auto auto 3rem !important;
    width: 2.15rem !important;
    height: 2.15rem !important;
    font-size: 0.85rem !important;
  }
}

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

@media (forced-colors: active) {
  .tile.correct,
  .tile.present,
  .tile.absent,
  .key.correct,
  .key.present,
  .key.absent,
  .legend-swatch {
    border: 2px solid CanvasText;
    forced-color-adjust: none;
  }
}
