:root {
  --bg-1: #f7f7ef;
  --bg-2: #e8efe4;
  --ink: #192017;
  --muted: #5c6759;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-strong: #ffffff;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warning: #b45309;
  --danger: #9f1239;
  --radius: 16px;
  --shadow: 0 20px 55px rgba(25, 32, 23, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Sora", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 15%, rgba(15, 118, 110, 0.2), transparent 40%),
    radial-gradient(circle at 90% 0%, rgba(180, 83, 9, 0.18), transparent 38%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
  padding: 24px 16px 14px;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(transparent 96%, rgba(0, 0, 0, 0.03) 96%);
  background-size: 100% 12px;
  opacity: 0.2;
}

.app {
  max-width: 600px;
  margin: 0 auto;
  border-radius: 24px;
  padding: clamp(16px, 2vw, 28px);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  animation: enter 420ms ease;
}

@keyframes enter {
  from {
    transform: translateY(8px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font: 600 0.72rem/1.4 "IBM Plex Mono", monospace;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.header-actions,
.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.control-buttons {
  margin-top: 22px;
  justify-content: center;
  row-gap: 10px;
}

.control-buttons .secondary-action {
  order: 2;
}

.control-buttons .primary-action {
  order: 1;
  flex: 0 0 100%;
  width: min(100%, 280px);
  margin: 0 auto;
  min-height: 48px;
  font-size: 1rem;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  color: #ffffff;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  font: 600 0.93rem/1 "Sora", sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 140ms ease, filter 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.button:active {
  transform: translateY(0);
}

.button:focus-visible,
.swatch:focus-visible,
.slot:focus-visible,
.switch-row input:focus-visible+span {
  outline: 2px solid #1f2937;
  outline-offset: 2px;
}

.button.ghost {
  color: var(--ink);
  background: transparent;
  border: 1px solid rgba(25, 32, 23, 0.28);
}

.button.subtle {
  color: #3a2300;
  background: linear-gradient(145deg, #f6d4a5, #efc37a);
}

.button.danger {
  color: #ffffff;
  background: linear-gradient(145deg, #c1121f, #9f1239);
}

.button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.status-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.status-card {
  background: var(--surface-strong);
  border-radius: 14px;
  border: 1px solid rgba(25, 32, 23, 0.09);
  min-width: 0;
  padding: 10px 10px;
}

.status-card span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.status-card strong {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
}

.board-card,
.controls {
  margin-top: 16px;
  background: var(--surface-strong);
  border: 1px solid rgba(25, 32, 23, 0.09);
  border-radius: var(--radius);
  padding: 14px;
}

.board {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.guess-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 86px;
  align-items: center;
  gap: 8px;
}

.guess-row.active {
  border-radius: 12px;
  padding: 8px 0;
  background: rgba(15, 118, 110, 0.08);
}

.guess-row.reveal-row {
  padding: 10px 0;
  border-radius: 12px;
  background: rgba(159, 18, 57, 0.08);
}

.slot,
.hole {
  width: 38px;
  height: 38px;
  justify-self: center;
  border-radius: 50%;
  border: 2px solid rgba(25, 32, 23, 0.18);
  background: #f0f3ee;
}

.piece-token {
  background-color: var(--piece-color, #f0f3ee);
}

body.color-safe-mode .piece-token {
  background-blend-mode: multiply;
}

body.color-safe-mode .piece-token[data-color-index="0"] {
  background-image: repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.35) 0 5px, transparent 5px 10px);
}

body.color-safe-mode .piece-token[data-color-index="1"] {
  background-image: radial-gradient(circle at 25% 25%, rgba(0, 0, 0, 0.38) 0 2px, transparent 2.5px);
  background-size: 10px 10px;
}

body.color-safe-mode .piece-token[data-color-index="2"] {
  background-image:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.28) 0 3px, transparent 3px 7px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.28) 0 3px, transparent 3px 7px);
}

body.color-safe-mode .piece-token[data-color-index="3"] {
  background-image: repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.35) 0 3px, transparent 3px 8px);
}

body.color-safe-mode .piece-token[data-color-index="4"] {
  background-image: repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.34) 0 4px, transparent 4px 9px);
}

body.color-safe-mode .piece-token[data-color-index="5"] {
  background-image:
    linear-gradient(45deg, rgba(0, 0, 0, 0.28) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.28) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.28) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.28) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.slot {
  cursor: pointer;
  touch-action: manipulation;
}

.swatch {
  touch-action: manipulation;
}

.slot.active {
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.22);
}

.submit-fly-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1200;
}

.submit-fly-stone {
  position: fixed;
  border-radius: 50%;
  border: 2px solid rgba(25, 32, 23, 0.18);
  box-shadow: 0 8px 16px rgba(25, 32, 23, 0.18);
}

.hole.landing {
  animation: landing-pulse 360ms ease-out;
}

@keyframes landing-pulse {
  0% {
    transform: scale(0.84);
    filter: brightness(1);
  }

  65% {
    transform: scale(1.08);
    filter: brightness(1.08);
  }

  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

.feedback {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  grid-auto-rows: 12px;
  gap: 4px;
  justify-content: end;
  padding-right: 6px;
}

.peg {
  border-radius: 50%;
  border: 1px solid rgba(25, 32, 23, 0.35);
  background: #e5e7eb;
}

.peg.black {
  background: #1f2937;
}

.peg.white {
  background: #ffffff;
}

.row-label {
  justify-self: end;
  padding-right: 6px;
  color: var(--danger);
  font: 700 0.72rem/1.2 "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.controls h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.palette {
  margin-top: 10px;
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.swatch {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  flex: 0 0 auto;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 2px solid rgba(25, 32, 23, 0.22);
  cursor: pointer;
}

.hint-output {
  margin-top: 10px;
  min-height: 22px;
  color: #4a2a00;
  font-weight: 600;
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.header-toggles {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  margin-left: auto;
  text-align: right;
}

.header-switch {
  margin-right: 0;
  font-size: 0.82rem;
  justify-content: flex-end;
}

.header-switch span {
  display: inline-block;
  max-width: 180px;
}

.switch-row input {
  width: 16px;
  height: 16px;
}

.announcement {
  margin-top: 12px;
  min-height: 24px;
  font-weight: 700;
}

.hint-modal,
.rules-modal {
  border: 0;
  border-radius: 16px;
  width: min(94vw, 520px);
  padding: 0;
  box-shadow: var(--shadow);
}

.hint-modal::backdrop,
.rules-modal::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.hint-modal article {
  padding: 18px;
}

.hint-modal p {
  margin: 10px 0 18px;
  color: var(--muted);
}

.hint-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.rules-modal article {
  padding: 18px;
}

.rules-modal ul {
  margin: 12px 0 14px;
  padding-left: 18px;
}

.app-footer {
  max-width: 600px;
  margin: 10px auto 0;
  padding: 6px 2px;
  font-size: 0.73rem;
  color: rgba(25, 32, 23, 0.66);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.app-footer a {
  color: inherit;
}

@media (max-width: 760px) {
  body {
    padding: 12px 10px 10px;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
  }

  .app-header>div:first-child {
    width: 100%;
  }

  .app-header h1 {
    font-size: 1.55rem;
  }

  .header-actions {
    width: 100%;
    min-width: 0;
    margin-left: 0;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .header-actions>* {
    flex: 1 1 0;
    min-width: 0;
  }

  .header-toggles {
    width: 100%;
    gap: 4px;
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  .header-switch {
    font-size: 0.68rem;
    gap: 4px;
    justify-content: space-between;
  }

  .header-actions .button {
    min-height: 34px;
    padding: 8px 9px;
    font-size: 0.72rem;
    width: 100%;
    white-space: nowrap;
  }

  .header-switch span {
    max-width: 58px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-switch input {
    width: 14px;
    height: 14px;
  }

  .status-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .status-card {
    padding: 8px 6px;
  }

  .status-card span {
    font-size: 0.68rem;
  }

  .status-card strong {
    font-size: 0.82rem;
  }

  .guess-row {
    grid-template-columns: repeat(4, minmax(0, 1fr)) 52px;
  }

  .button {
    min-height: 44px;
    padding: 12px 16px;
  }

  .control-buttons {
    gap: 8px;
    justify-content: center;
  }

  .control-buttons .button {
    flex: 0 1 auto;
  }

  .control-buttons .primary-action {
    flex-basis: 100%;
    width: min(100%, 320px);
  }

  .swatch {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .slot,
  .hole {
    width: 44px;
    height: 44px;
  }

  .app-footer {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}