:root {
  color-scheme: light;
  --bg: #f7f3eb;
  --paper: #fffaf0;
  --ink: #23303f;
  --muted: #647083;
  --line: #d9d1c3;
  --teal: #187b78;
  --teal-dark: #0f5d5b;
  --coral: #e35d4f;
  --gold: #f0b84f;
  --green: #4d8f59;
  --card-back: #36516a;
  --card-back-2: #24374b;
  --focus: #1c6fe8;
  --shadow: 0 18px 50px rgba(31, 42, 56, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(240, 184, 79, 0.24), transparent 26rem),
    linear-gradient(135deg, #f7f3eb 0%, #e8f0ec 45%, #f3edf7 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  align-items: center;
}

.screen {
  width: 100%;
}

.is-hidden {
  display: none !important;
}

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

.title-screen {
  display: grid;
  gap: 30px;
  justify-items: center;
  text-align: center;
}

.setup-screen {
  display: grid;
  justify-items: center;
  align-items: center;
}

.setup-copy h1,
.game-header h1 {
  margin: 0;
  font-size: clamp(2.25rem, 6vw, 5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.setup-copy h1 {
  max-width: 7ch;
}

.title-screen .setup-copy h1 {
  max-width: none;
}

.title-screen .intro {
  margin-right: auto;
  margin-left: auto;
}

.intro {
  max-width: 28rem;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 1.18rem;
  line-height: 1.5;
}

.setup-panel {
  width: min(100%, 760px);
  padding: 24px;
  background: rgba(255, 250, 240, 0.88);
  border: 1px solid rgba(217, 209, 195, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.setup-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.setup-column {
  min-width: 0;
}

.setup-column h2 {
  margin: 0 0 16px;
  font-size: 1.3rem;
  line-height: 1;
}

.setup-section-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px;
}

.setup-section-header h2 {
  margin: 0;
}

.player-fields {
  display: grid;
  gap: 14px;
}

.player-field-row.has-remove-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.player-fields .field {
  min-width: 0;
  margin-bottom: 0;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  color: var(--ink);
  font-weight: 800;
}

.field span,
.card-count-picker legend {
  font-size: 0.95rem;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
  border: 2px solid transparent;
  border-radius: 8px;
  outline: 1px solid var(--line);
}

.field input:focus,
.field select:focus {
  border-color: var(--focus);
  outline-color: transparent;
}

.card-count-picker {
  margin: 0;
  padding: 0;
  border: 0;
}

.card-count-picker legend {
  margin: 0 0 10px;
  font-weight: 800;
}

.count-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}

.count-option {
  min-height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
  border: 2px solid transparent;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 900;
}

.count-option[aria-checked="true"] {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(24, 123, 120, 0.16);
}

.deck-field {
  margin-bottom: 0;
}

.checkbox-field {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 18px;
  color: var(--ink);
  font-weight: 900;
}

.checkbox-field input {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
  flex: 0 0 auto;
}

.add-player-button {
  width: 42px;
  min-height: 42px;
  padding: 0;
  color: white;
  background: var(--teal);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(24, 123, 120, 0.18);
  font-size: 1.7rem;
  line-height: 1;
  font-weight: 900;
}

.add-player-button:hover:not(:disabled),
.add-player-button:focus-visible {
  background: var(--teal-dark);
}

.add-player-button:disabled {
  color: #7c8796;
  background: #d7dce2;
  box-shadow: inset 0 0 0 1px #c6cdd6;
}

.remove-player-button {
  width: 48px;
  min-height: 48px;
  padding: 0;
  color: #aa2c25;
  background: white;
  border: 0;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 1rem;
  line-height: 1;
  font-weight: 900;
}

.remove-player-button:hover,
.remove-player-button:focus-visible {
  background: #fff1ef;
  box-shadow: inset 0 0 0 2px var(--coral);
}

.error-message {
  min-height: 1.35rem;
  margin: 14px 0 12px;
  color: #aa2c25;
  font-weight: 800;
}

.mode-actions {
  width: min(100%, 540px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mode-action {
  min-height: 78px;
  padding: 0 18px;
  color: var(--ink);
  background: white;
  border: 2px solid transparent;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--line), 0 10px 22px rgba(31, 42, 56, 0.1);
  font-size: 1.28rem;
  font-weight: 900;
}

.mode-action:hover,
.mode-action:focus-visible {
  border-color: var(--teal);
}

.mode-action-primary {
  color: white;
  background: var(--teal);
  box-shadow: 0 10px 22px rgba(24, 123, 120, 0.22);
}

.mode-action-primary:hover,
.mode-action-primary:focus-visible {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
}

.setup-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.primary-action,
.secondary-action,
.icon-action {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  font-weight: 900;
}

.primary-action {
  width: 100%;
  color: white;
  background: var(--teal);
  box-shadow: 0 10px 22px rgba(24, 123, 120, 0.22);
}

.primary-action:hover {
  background: var(--teal-dark);
}

.secondary-action {
  padding: 0 16px;
  color: var(--ink);
  background: white;
  box-shadow: inset 0 0 0 1px var(--line);
}

.icon-action {
  flex: 0 0 auto;
  width: 46px;
  padding: 0;
  color: var(--ink);
  background: white;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 1.5rem;
  line-height: 1;
}

.icon-action:hover {
  background: #eef7f4;
}

.is-playing .app-shell {
  padding-top: 0;
  align-items: start;
}

.gameplay-screen {
  display: grid;
  gap: 12px;
  align-items: start;
}

.game-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px;
  background: rgba(255, 250, 240, 0.94);
  border: 1px solid rgba(217, 209, 195, 0.9);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 10px 30px rgba(31, 42, 56, 0.12);
  backdrop-filter: blur(12px);
}

.game-header h1 {
  font-size: clamp(1.35rem, 3vw, 2.6rem);
  line-height: 1;
}

.title-glyph {
  margin-right: 0.08em;
}

.score-board {
  --score-count: 2;
  flex: 1 1 520px;
  min-width: min(100%, 280px);
  display: grid;
  grid-template-columns: repeat(var(--score-count), minmax(118px, 1fr));
  gap: 10px;
}

.score-card {
  min-width: 0;
  min-height: 46px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name value";
  gap: 10px;
  align-items: center;
  background: rgba(255, 250, 240, 0.86);
  border: 2px solid transparent;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.score-card.is-active {
  border-color: var(--gold);
  background: #fff7dc;
  box-shadow: 0 0 0 4px rgba(240, 184, 79, 0.2);
}

.score-card.is-timer {
  background: #eef7f4;
}

.score-card.is-warning {
  border-color: var(--coral);
  background: #fff1ef;
  box-shadow: 0 0 0 4px rgba(227, 93, 79, 0.16);
}

.score-name {
  grid-area: name;
  min-width: 0;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.score-value {
  grid-area: value;
  font-size: 1.8rem;
  line-height: 1;
}

.cards-left {
  flex: 0 0 auto;
  margin: 0 0 0 auto;
  padding: 0 2px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
}

.card-grid {
  --columns: 6;
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(44px, 1fr));
  gap: clamp(6px, 1.1vw, 12px);
  align-items: stretch;
}

.memory-card {
  position: relative;
  aspect-ratio: 15 / 16;
  min-height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  color: white;
  background: linear-gradient(145deg, var(--card-back), var(--card-back-2));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(34, 45, 60, 0.18);
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.memory-card::before {
  content: "";
  position: absolute;
  inset: 12%;
  display: block;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.46) 1.5px, transparent 1.8px) 0 0 / 14px 14px,
    linear-gradient(45deg, transparent 44%, rgba(255, 255, 255, 0.18) 45% 55%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, rgba(255, 255, 255, 0.12) 45% 55%, transparent 56%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.memory-card::after {
  content: "";
  position: absolute;
  width: 27%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  transform: rotate(45deg);
}

.memory-card:hover:not(:disabled),
.memory-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 12px 20px rgba(34, 45, 60, 0.22);
}

.memory-card:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.memory-card.is-revealed,
.memory-card.is-matched {
  color: var(--ink);
  background: #fffaf0;
  box-shadow: inset 0 0 0 2px var(--line), 0 6px 12px rgba(34, 45, 60, 0.12);
}

.memory-card.is-revealed::before,
.memory-card.is-matched::before {
  content: attr(data-symbol);
  position: static;
  inset: auto;
  width: auto;
  aspect-ratio: auto;
  display: block;
  border: 0;
  background: none;
  box-shadow: none;
  font-size: clamp(1.65rem, 5vw, 3.1rem);
  line-height: 1;
}

.memory-card.is-revealed::after,
.memory-card.is-matched::after {
  display: none;
}

.memory-card.is-matched {
  background: #e9f7df;
  box-shadow: inset 0 0 0 3px rgba(77, 143, 89, 0.5);
}

.winner-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(35, 48, 63, 0.38);
}

.winner-panel {
  width: min(100%, 360px);
  padding: 24px;
  color: var(--ink);
  text-align: center;
  background: var(--paper);
  border: 1px solid rgba(217, 209, 195, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.winner-panel h2 {
  margin: 0 0 18px;
  font-size: 2rem;
  line-height: 1.1;
}

.winner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.solo-start-actions {
  grid-template-columns: 1fr;
}

.winner-actions .primary-action,
.winner-actions .secondary-action {
  width: 100%;
  min-width: 0;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding: 20px 0;
  }

  .setup-screen,
  .setup-columns {
    grid-template-columns: 1fr;
  }

  .setup-copy h1 {
    max-width: none;
  }

  .intro {
    margin-top: 12px;
  }
}

@media (max-width: 560px) {
  .setup-columns {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .setup-actions {
    grid-template-columns: 1fr;
  }

  .mode-action {
    min-height: 64px;
    font-size: 1.12rem;
  }

  .setup-panel {
    padding: 16px;
  }

  .game-header {
    gap: 6px;
    padding: 8px;
  }

  .score-board {
    order: 4;
    flex-basis: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .score-card {
    padding: 7px 8px;
  }

  .score-name {
    font-size: 0.9rem;
  }

  .score-value {
    font-size: 1.35rem;
  }

  .card-grid {
    gap: 6px;
  }

  .memory-card {
    min-height: 40px;
  }

  .winner-actions {
    grid-template-columns: 1fr;
  }
}
