:root {
  color-scheme: light;
  --ink: #2f2d38;
  --muted: #6c687a;
  --cream: #fff8e8;
  --panel: #ffffff;
  --orange: #f2b35d;
  --orange-dark: #a85f1f;
  --mint: #8bd2b8;
  --blue: #83b7ec;
  --pink: #ee8fa3;
  --shadow: 0 12px 28px rgba(84, 56, 30, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 18%, rgba(139, 210, 184, 0.44), transparent 24%),
    linear-gradient(180deg, #fff0c9 0%, #f7fbff 56%, #d6ecff 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
  user-select: none;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

a {
  color: inherit;
}

.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 12px;
  min-height: 100svh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.top-bar,
.status-panel,
.controls,
.answer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--orange-dark);
  font-size: 1rem;
  font-weight: 850;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.4rem);
  line-height: 1;
}

.home-link,
.start-button,
.reset-button,
.chip,
.settings-summary,
.answer-button {
  min-height: 46px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(168, 95, 31, 0.2);
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--panel);
  box-shadow: 0 7px 0 rgba(168, 95, 31, 0.13);
  font-weight: 900;
  text-decoration: none;
}

.start-button,
.answer-button {
  color: #fff;
  background: var(--orange-dark);
}

.same-button {
  color: var(--ink);
  background: var(--mint);
}

.sound-button {
  background: #fff8e8;
}

.status-panel {
  min-height: 88px;
  border: 3px solid rgba(168, 95, 31, 0.18);
  border-radius: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.label,
.big-text,
.message {
  margin: 0;
  text-align: center;
  font-weight: 900;
}

.label {
  color: var(--muted);
  font-size: 0.9rem;
}

.big-text {
  min-width: 54px;
  font-size: 2rem;
  line-height: 1;
}

.small-text {
  font-size: 1.6rem;
}

.message-box {
  flex: 1;
}

.message {
  color: var(--orange-dark);
  font-size: clamp(1.05rem, 3vw, 1.45rem);
}

.compare-stage {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 3vw, 18px);
}

.side-card {
  min-height: 360px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  border: 4px solid rgba(168, 95, 31, 0.2);
  border-radius: 8px;
  padding: clamp(10px, 3vw, 18px);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.side-card.is-right {
  background: #fff4c5;
}

.side-card.is-wrong {
  background: #ffdbe4;
  animation: shake 260ms ease;
}

.side-title {
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 950;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(30px, 1fr));
  align-content: center;
  justify-items: center;
  gap: clamp(8px, 2vw, 14px);
}

.count-item {
  width: min(54px, 100%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 4px solid rgba(255, 255, 255, 0.84);
  border-radius: 50%;
  background: linear-gradient(145deg, var(--orange), #ffd98d);
  box-shadow: 0 8px 14px rgba(84, 56, 30, 0.14);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 950;
  transform: translate(var(--shift-x, 0), var(--shift-y, 0)) rotate(var(--tilt, 0deg));
}

.count-item:nth-child(2n) {
  background: linear-gradient(145deg, var(--blue), #b9d9f8);
}

.count-item:nth-child(3n) {
  background: linear-gradient(145deg, var(--pink), #ffd1dc);
}

.count-item.is-distractor {
  opacity: 0.58;
  border-color: rgba(108, 104, 122, 0.28);
  background: #d8d2c8;
  box-shadow: none;
}

.count-item.line {
  height: 16px;
  aspect-ratio: auto;
  border-radius: 999px;
}

.count-item.triangle {
  width: min(44px, 100%);
  border-radius: 8px;
  clip-path: polygon(50% 8%, 92% 86%, 8% 86%);
}

.count-item.ghost {
  width: min(40px, 100%);
  background: transparent;
  border-style: dashed;
}

.answer-row {
  justify-content: center;
}

.answer-button {
  min-width: min(150px, 31%);
  font-size: clamp(1rem, 3.8vw, 1.35rem);
}

.controls {
  justify-content: center;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.settings-panel {
  flex: 1 1 100%;
}

.settings-summary {
  cursor: pointer;
  list-style: none;
}

.settings-summary::-webkit-details-marker {
  display: none;
}

.settings-body {
  margin-top: 8px;
}

.chip.is-active {
  color: #fff;
  background: var(--orange-dark);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@media (max-width: 700px) {
  .app {
    gap: 9px;
    padding: 12px;
  }

  .eyebrow {
    display: none;
  }

  .top-bar {
    align-items: start;
  }

  h1 {
    font-size: 2rem;
  }

  .home-link,
  .start-button,
  .reset-button,
  .chip,
  .settings-summary,
  .answer-button {
    min-height: 42px;
    padding: 7px 10px;
  }

  .status-panel {
    min-height: 72px;
    padding: 7px;
  }

  .label {
    font-size: 0.78rem;
  }

  .big-text {
    min-width: 42px;
    font-size: 1.55rem;
  }

  .message {
    font-size: 1rem;
  }

  .side-card {
    min-height: 300px;
    padding: 9px;
  }

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

  .count-item {
    width: min(46px, 100%);
    font-size: 1rem;
  }
}

@media (max-width: 390px) {
  .side-card {
    min-height: 260px;
  }

  .count-item {
    width: min(40px, 100%);
  }
}
