:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --page: #eeebe2;
  --ink: #2b2635;
  --muted: #625b6a;
  --line: #d6d0c7;
  --surface: #faf8f2;
  --tray: #302a39;
  --tile-face: #f5f4f0;
  --tile-edge: #d5d2cb;
  --letters: "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  display: flow-root;
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  background-color: var(--page);
  background-image: radial-gradient(ellipse at 50% 20%, #fffdf5d9, transparent 70%),
    radial-gradient(#493d3219 0.6px, transparent 0.7px);
  background-size: 100% 100%, 14px 14px;
  color: var(--ink);
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button:not(:disabled) {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid #6d5492;
  outline-offset: 3px;
}

.layout {
  display: grid;
  gap: 24px;
  width: min(380px, calc(100% - 36px));
  margin: clamp(24px, 8vh, 76px) auto 32px;
}

.mode-switch {
  display: inline-flex;
  justify-self: center;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #e8e2d8;
}

.mode-switch button {
  min-height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.mode-switch button:hover {
  color: var(--ink);
}

.mode-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px #3c314024;
}

.game-column {
  display: grid;
  gap: 16px;
}

.target-area {
  display: flex;
  align-items: center;
  justify-content: center;
}

.target-badge {
  position: relative;
  display: grid;
  place-items: center;
  width: 49px;
  height: 43px;
  padding-bottom: 3px;
  font: 500 25px/1 var(--letters);
}

.target-letters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 102px);
  min-width: 0;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.target-letter {
  position: relative;
}

.target-letter input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.target-letter span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--surface);
  font: 500 19px/1 var(--letters);
}

.target-letter input:checked + span,
.target-letter input:focus-visible + span {
  text-decoration: underline;
  text-underline-offset: 0.24em;
}

.target-letter input:checked + span {
  font-weight: 700;
}

.target-letter input:focus-visible + span {
  text-decoration-style: dashed;
}

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

.tile {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0 0 4px;
  border: 1px solid #2e23301f;
  background-color: var(--tile-face);
  font: 500 18px/1 var(--letters);
}

.board-tiles {
  padding: 11px;
  border: 1px solid #3e364a;
  border-radius: 24px;
  background: linear-gradient(160deg, #42394e, var(--tray) 65%);
  box-shadow: 0 4px 0 #221d2a, 0 21px 37px -19px #392c4c8f;
}

.board-tiles .tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  background-image: linear-gradient(160deg, #ffffff28, transparent 57%);
  box-shadow: inset 0 1px 0 #ffffff6b, inset 0 -5px 0 var(--tile-edge);
  font-size: clamp(30px, 10vw, 43px);
}

.tile-glyph {
  display: block;
}

.letter-firework {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

button.tile {
  transition: filter 120ms ease;
}

@media (hover: hover) {
  .board-tiles:not([aria-busy="true"]) button.tile:hover {
    filter: brightness(1.07);
  }
}

.board-tiles[aria-busy="true"] button.tile {
  cursor: default;
}

.board-tiles button:focus-visible {
  outline-color: white;
  outline-offset: 1px;
}

.board-tiles.complete {
  outline: 2px solid #8d9f52;
  outline-offset: 3px;
}

.status {
  align-self: center;
  padding-inline: 2px;
  color: #57602c;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.status.impossible {
  color: #9d402f;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 5px;
}

.action {
  flex: 1 0 auto;
  min-height: 43px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.action-icon {
  display: grid;
  place-items: center;
}

.icon {
  display: block;
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action-primary {
  flex-grow: 1.6;
  border-color: #3e354a;
  background: var(--tray);
  color: #fffaf4;
  box-shadow: 0 2px 3px #3d314826;
}

.action-primary:hover:not(:disabled) {
  background: #473b54;
}

.action-secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
}

.action-secondary:hover:not(:disabled),
.action-secondary[aria-expanded="true"] {
  border-color: #bcb0c3;
  color: var(--ink);
}

.action:disabled {
  opacity: 0.48;
}

.answer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.answer-steps {
  margin: 0;
  font: 500 17px/1.65 var(--letters);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.close-answer {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.close-answer:hover {
  background: #eee9e1;
  color: var(--ink);
}

.close-answer .icon {
  width: 18px;
  height: 18px;
}

@media (max-width: 380px) {
  .layout {
    gap: 20px;
  }

  .action {
    padding-inline: 8px;
    font-size: 12px;
  }

  .board-tiles {
    border-radius: 20px;
  }

  .board-tiles .tile {
    border-radius: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  button.tile {
    transition: none;
  }
}
