:root {
  color-scheme: light;
  --ink: #17312d;
  --muted: #5c6f69;
  --paper: #fffdf6;
  --paper-edge: #e7dfcc;
  --cream: #f6f0df;
  --green-900: #173f35;
  --green-700: #246756;
  --green-500: #3d8b73;
  --orange: #ee8b4b;
  --orange-dark: #b95021;
  --desk: #9d6039;
  --desk-dark: #724127;
  --danger: #a5322b;
  --shadow: 0 18px 42px rgb(31 47 42 / 18%);
  --focus: 0 0 0 4px rgb(238 139 75 / 38%);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #eef1e8;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 12%, rgb(255 255 255 / 80%), transparent 28rem),
    linear-gradient(145deg, #f2f3e9 0%, #e3ece4 100%);
}

.legal-page {
  min-height: 100vh;
  padding: clamp(1.25rem, 4vw, 3rem);
}

.legal-panel {
  width: min(100%, 48rem);
  margin: 0 auto;
  padding: clamp(1.5rem, 5vw, 3.5rem);
  border: 1px solid rgb(255 255 255 / 22%);
  border-radius: 1.25rem;
  background: rgb(250 247 238 / 96%);
  color: #173f35;
  box-shadow: 0 1.5rem 4rem rgb(19 48 40 / 28%);
}

.legal-panel h1 {
  margin-top: 0;
}

.legal-panel h2 {
  margin: 2rem 0 0.5rem;
  font-size: 1.15rem;
}

.legal-panel p {
  line-height: 1.7;
}

.legal-updated {
  color: #526a63;
  font-size: 0.9rem;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.7rem 1rem;
  color: white;
  background: var(--green-900);
  border-radius: 0.5rem;
  transform: translateY(-200%);
}

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

.screen {
  min-height: 100vh;
}

.start-screen {
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.start-panel {
  position: relative;
  width: min(100%, 34rem);
  padding: clamp(2rem, 5vw, 3.5rem);
  overflow: hidden;
  background:
    linear-gradient(rgb(255 253 246 / 96%), rgb(255 253 246 / 96%)),
    repeating-linear-gradient(0deg, transparent 0 1.7rem, #cddcec 1.72rem 1.76rem);
  border: 1px solid var(--paper-edge);
  border-radius: 1.5rem 1.5rem 1.5rem 0.4rem;
  box-shadow: var(--shadow), 0.65rem 0.65rem 0 #d5dfd5;
}

.start-panel::after {
  position: absolute;
  right: -4.5rem;
  bottom: -5.5rem;
  width: 11rem;
  height: 11rem;
  content: "";
  background: var(--orange);
  border-radius: 50%;
  opacity: 0.14;
}

.brand-mark {
  display: flex;
  width: 4.6rem;
  height: 3.5rem;
  margin-bottom: 1.4rem;
  align-items: center;
  justify-content: center;
}

.brand-mark span {
  position: absolute;
  width: 3.2rem;
  height: 2.25rem;
  background: var(--paper);
  border: 2px solid var(--green-900);
  border-radius: 0.35rem;
  box-shadow: 0 3px 0 rgb(23 63 53 / 12%);
}

.brand-mark span:nth-child(1) { transform: rotate(-9deg) translate(-0.35rem, 0.15rem); }
.brand-mark span:nth-child(2) { transform: rotate(8deg) translate(0.45rem, 0.1rem); }
.brand-mark span:nth-child(3) { transform: translateY(-0.25rem); background: #fff6d8; }

.eyebrow,
.zone-kicker {
  margin: 0 0 0.35rem;
  color: var(--green-700);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  text-wrap: pretty;
}

.start-panel h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.8rem, 9vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: -0.055em;
}

.intro {
  max-width: 28rem;
  margin: 1rem 0 2rem;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

#start-form {
  display: grid;
  gap: 0.65rem;
}

#start-form label {
  margin-top: 0.55rem;
  font-size: 0.9rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  padding: 0.92rem 1rem;
  color: var(--ink);
  background: white;
  border: 1px solid #bec9c4;
  border-radius: 0.7rem;
}

input:hover,
select:hover {
  border-color: var(--green-500);
}

input[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--danger);
}

.form-message,
.game-message {
  min-height: 1.25rem;
  margin: 0.25rem 0 0;
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 650;
}

.environment-note {
  margin: 1.4rem 0 0;
  padding: 0.75rem 0.9rem;
  color: #70421f;
  background: #fff2cf;
  border: 1px solid #e8cc87;
  border-radius: 0.65rem;
  font-size: 0.82rem;
  line-height: 1.45;
}

.button {
  display: inline-flex;
  min-height: 2.75rem;
  padding: 0.72rem 1.1rem;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--ink);
  background: white;
  border: 1px solid rgb(23 49 45 / 22%);
  border-radius: 0.7rem;
  font-weight: 800;
  transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgb(23 49 45 / 14%);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-primary {
  color: white;
  background: var(--green-900);
  border-color: var(--green-900);
}

.button-primary:hover:not(:disabled) {
  background: var(--green-700);
}

.button-large {
  min-height: 3.25rem;
  margin-top: 0.8rem;
  font-size: 1.03rem;
}

.button-secondary {
  color: var(--green-900);
  background: #f9fbf6;
}

.button-finish {
  min-width: 7.5rem;
  color: white;
  background: var(--orange-dark);
  border-color: var(--orange-dark);
}

.game-screen {
  padding-bottom: 3rem;
  background: #edf1e9;
}

.game-header,
.game-toolbar {
  display: flex;
  width: min(100% - 2rem, 90rem);
  margin-inline: auto;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.game-header {
  padding: 1.25rem 0 0.9rem;
}

.game-header h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 3vw, 2.4rem);
}

.game-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}

.progress-pill,
.count-badge {
  display: inline-flex;
  padding: 0.38rem 0.7rem;
  color: var(--green-900);
  background: #dce9df;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.game-toolbar {
  padding: 0.8rem 1rem;
  background: rgb(255 255 255 / 76%);
  border: 1px solid rgb(23 49 45 / 10%);
  border-radius: 0.9rem;
  box-shadow: 0 6px 20px rgb(23 49 45 / 8%);
  backdrop-filter: blur(8px);
}

.game-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar-actions {
  display: flex;
  gap: 0.65rem;
}

.game-message {
  width: min(100% - 2rem, 90rem);
  margin: 0.6rem auto;
  text-align: right;
}

.game-message.is-success {
  color: var(--green-700);
}

.desk {
  position: relative;
  width: min(100% - 2rem, 90rem);
  min-height: 65vh;
  margin: 0 auto;
  padding: clamp(1rem, 2.5vw, 2rem);
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 0 49.6%, rgb(54 24 11 / 7%) 49.8% 50.1%, transparent 50.3%),
    repeating-linear-gradient(92deg, rgb(255 255 255 / 2%) 0 5rem, rgb(53 24 11 / 5%) 5.1rem 5.2rem),
    linear-gradient(125deg, #ad724a, var(--desk) 55%, var(--desk-dark));
  border: 0.55rem solid #684029;
  border-radius: 1.15rem;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 12%), 0 20px 45px rgb(47 36 27 / 28%);
}

.card-zone,
.groups-section {
  position: relative;
  padding: 1rem;
  border-radius: 0.85rem;
}

.unsorted-zone {
  min-height: 11.5rem;
  margin-bottom: 1rem;
  background: rgb(44 25 15 / 18%);
  border: 2px dashed rgb(255 255 255 / 35%);
}

.card-zone.is-drag-over,
.group-tray.is-drag-over {
  background: rgb(255 244 198 / 24%);
  border-color: #ffe5a7;
  box-shadow: inset 0 0 0 3px rgb(255 229 167 / 22%);
}

.zone-heading,
.groups-heading,
.group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.zone-heading h2,
.groups-heading h2,
.group-heading h3 {
  margin: 0;
  color: white;
  text-shadow: 0 1px 1px rgb(45 23 13 / 38%);
}

.zone-heading h2,
.groups-heading h2 {
  font-size: 1.1rem;
}

.zone-kicker {
  color: #f5dcbf;
  font-size: 0.65rem;
}

.count-badge {
  color: #4e2a16;
  background: #f6dfb7;
}

.cards-layout {
  display: flex;
  min-height: 6.8rem;
  padding: 0.8rem 0.4rem 0.2rem;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.75rem;
}

.flash-card {
  position: relative;
  display: grid;
  width: 9.2rem;
  min-height: 5.9rem;
  padding: 0.85rem;
  place-items: center;
  color: #283b37;
  background:
    repeating-linear-gradient(0deg, transparent 0 1.24rem, #dfe8eb 1.27rem 1.31rem),
    var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 0.42rem;
  box-shadow: 0 7px 13px rgb(44 25 15 / 24%), 0 2px 2px rgb(44 25 15 / 16%);
  font-size: 0.98rem;
  font-weight: 850;
  line-height: 1.25;
  text-align: center;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
  user-select: none;
  touch-action: none;
}

.flash-card::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0.65rem;
  width: 1px;
  content: "";
  background: #f1b7ae;
}

.flash-card:hover,
.flash-card:focus-visible,
.flash-card.is-selected {
  z-index: 2;
  box-shadow: 0 13px 20px rgb(44 25 15 / 30%);
  transform: translateY(-5px) rotate(0deg);
}

.flash-card.is-selected {
  outline: 3px solid #ffd177;
}

.flash-card.is-dragging {
  opacity: 0.35;
  transform: translateY(-10px) rotate(0deg) scale(1.03);
}

.groups-section {
  padding-inline: 0;
}

.groups-heading {
  padding: 0.25rem 0.25rem 0.75rem;
}

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  gap: 0.9rem;
}

.group-tray {
  min-height: 12rem;
  padding: 0.85rem;
  background:
    linear-gradient(rgb(250 242 214 / 91%), rgb(241 226 187 / 91%)),
    repeating-linear-gradient(90deg, #e9d5a8 0 3rem, #ddc38d 3.1rem 3.2rem);
  border: 2px solid #ddbd7d;
  border-radius: 0.7rem 0.7rem 1rem 1rem;
  box-shadow: inset 0 -5px 0 rgb(130 81 39 / 10%), 0 8px 13px rgb(44 25 15 / 19%);
  transition: background-color 140ms ease, box-shadow 140ms ease;
}

.group-heading {
  padding-bottom: 0.55rem;
  border-bottom: 1px solid rgb(107 66 27 / 18%);
}

.group-heading h3 {
  color: #51311e;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  text-shadow: none;
}

.remove-group {
  padding: 0.3rem 0.45rem;
  color: #7b4934;
  background: transparent;
  border: 0;
  border-radius: 0.35rem;
  font-size: 0.76rem;
  font-weight: 800;
}

.remove-group:hover:not(:disabled) {
  color: var(--danger);
  background: rgb(255 255 255 / 48%);
}

.remove-group:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.group-cards {
  min-height: 7.2rem;
  padding-inline: 0;
}

.empty-hint {
  width: 100%;
  margin: auto;
  color: rgb(81 49 30 / 62%);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.results-dialog {
  position: relative;
  width: min(calc(100% - 2rem), 34rem);
  padding: clamp(2rem, 6vw, 3.5rem);
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 1.25rem;
  box-shadow: 0 28px 80px rgb(9 28 23 / 35%);
  text-align: center;
}

.results-dialog::backdrop {
  background: rgb(13 36 31 / 72%);
  backdrop-filter: blur(5px);
}

.results-dialog[open] {
  animation: score-in 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.results-dialog h2 {
  position: relative;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
}

.score-display {
  position: relative;
  display: flex;
  margin: 1.25rem 0 0.8rem;
  align-items: baseline;
  justify-content: center;
  gap: 0.45rem;
  color: var(--green-900);
}

.score-display strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(5rem, 18vw, 8rem);
  line-height: 0.9;
  letter-spacing: -0.08em;
}

.score-display span {
  font-size: 1.2rem;
  font-weight: 800;
}

.results-copy {
  position: relative;
  color: var(--muted);
}

.results-actions {
  position: relative;
  display: flex;
  margin-top: 1.5rem;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.score-rays {
  position: absolute;
  inset: -35%;
  background: repeating-conic-gradient(from 0deg, rgb(238 139 75 / 8%) 0deg 7deg, transparent 7deg 19deg);
  animation: rays 18s linear infinite;
}

@keyframes score-in {
  from { opacity: 0; transform: translateY(1.5rem) scale(0.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes rays {
  to { transform: rotate(360deg); }
}

@media (max-width: 720px) {
  .game-header,
  .game-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .game-meta,
  .toolbar-actions {
    justify-content: space-between;
  }

  .toolbar-actions .button {
    flex: 1;
  }

  .game-message {
    text-align: left;
  }

  .desk {
    width: calc(100% - 1rem);
    padding: 0.75rem;
  }

  .flash-card {
    width: calc(50% - 0.4rem);
    min-width: 7rem;
  }
}

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