:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #faf8f3;
  --surface-hover: #fffdfa;
  --text: #37372f;
  --muted: #707067;
  --line: #d9d4ca;
  --accent: #a86b50;
  --accent-soft: #ead4c8;
  --shadow: 0 14px 40px rgba(58, 48, 39, 0.13);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1f211f;
  --surface: #292c29;
  --surface-hover: #323632;
  --text: #f2eee5;
  --muted: #b8b4aa;
  --line: #464a45;
  --accent: #e0a07e;
  --accent-soft: #5b3d31;
  --shadow: 0 16px 46px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Arial Narrow", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  transition: background-color 180ms ease, color 180ms ease;
}

button, textarea, input { font: inherit; }

button { color: inherit; }

button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 58%, transparent);
  outline-offset: 3px;
}

.site-header {
  display: grid;
  grid-template-columns: minmax(270px, 1fr) auto minmax(150px, 1fr);
  align-items: center;
  gap: 20px;
  padding: 22px 26px 18px;
}

.site-header h1 {
  margin: 0;
  text-align: center;
  font-family: Impact, "Arial Narrow", "PingFang SC", sans-serif;
  font-size: clamp(2.2rem, 4.1vw, 4.5rem);
  font-style: italic;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button, .upload-button, .category-title, .game-panel, .modal {
  border: 1px solid var(--line);
  background: var(--surface);
}

.icon-button, .upload-button {
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--surface-text, var(--text));
  transition: transform 150ms ease, background-color 150ms ease;
}

.icon-button:hover, .upload-button:hover { background: var(--surface-hover); transform: translateY(-1px); }

.icon-button {
  width: 44px;
  padding: 0;
  font-family: Georgia, serif;
  font-size: 1.25rem;
  font-weight: 700;
}

.upload-button {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  font-size: 0.95rem;
  font-weight: 700;
}

.date-block {
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  line-height: 1.2;
}

.date-block time { font-size: 1.15rem; font-weight: 700; }
.date-block span { color: var(--muted); font-size: 0.82rem; }

main {
  display: flex;
  flex: 1 0 auto;
  padding: 0 24px;
}

.board {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(var(--category-columns, 6), minmax(0, 1fr));
  grid-auto-rows: minmax(min-content, 1fr);
  align-items: stretch;
  gap: 12px;
  width: 100%;
  max-width: none;
  margin: 0 auto;
}

.category {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  min-width: 0;
}

.category-title {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70px;
  margin: 0;
  padding: 10px;
  border-top: 3px solid var(--accent);
  border-radius: 10px;
  font-size: clamp(1.05rem, 1.5vw, 1.5rem);
  font-style: italic;
  font-weight: 800;
  text-align: center;
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(118px, 1fr));
  gap: 10px;
}

.score-card {
  position: relative;
  min-width: 0;
  min-height: clamp(118px, 20vh, 190px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--surface-text, var(--text));
  cursor: pointer;
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: clamp(2rem, 3vw, 3.6rem);
  font-style: italic;
  transition: transform 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.score-card:hover { transform: translateY(-3px); background: var(--surface-hover); box-shadow: var(--shadow); }
.score-card:active { transform: translateY(0) scale(0.985); }

.score-card.used {
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 70%, var(--accent-soft));
}

.score-card.used.success {
  color: #315d43;
  background: #e3f1e5;
}

.score-card.used.failure {
  color: #87504b;
  background: #f3e2df;
}

.board.few-categories .category-title {
  min-height: 82px;
  font-size: clamp(1.4rem, 3vw, 2.5rem);
}

.board.few-categories .score-card {
  min-height: max(150px, calc((100vh - 250px) / 3));
  font-size: clamp(3rem, 7vw, 6rem);
}

.score-card.used::after {
  content: "✓";
  position: absolute;
  top: 9px;
  right: 11px;
  color: var(--accent);
  font-family: Arial, sans-serif;
  font-size: 1rem;
  font-style: normal;
  font-weight: 800;
}

footer {
  flex: 0 0 auto;
  padding: 18px 24px 22px;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 0.78rem;
  font-style: italic;
  letter-spacing: 0.08em;
  text-align: center;
}

[hidden] { display: none !important; }

.overlay, .modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(12px);
}

.overlay {
  padding: 0;
  background: var(--bg);
  backdrop-filter: none;
  transition: background-color 420ms ease;
}

.overlay.outcome-success {
  background: color-mix(in srgb, #dff2e3 86%, var(--bg));
  animation: successWash 700ms ease both;
}

.overlay.outcome-failure {
  background: color-mix(in srgb, #f5dedb 88%, var(--bg));
  animation: failureWash 780ms ease both;
}

.game-panel {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: clamp(28px, 6vw, 72px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
  color: var(--text);
}

.game-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: clamp(1.7rem, 3vw, 3rem);
  font-weight: 800;
  animation: questionIn 460ms cubic-bezier(.2,.85,.25,1) both;
}

.game-meta strong {
  padding: 0;
  background: transparent;
  color: var(--text);
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: clamp(4.5rem, 10vw, 8.5rem);
  font-style: italic;
  line-height: 1;
}

.ready-state { max-width: 520px; }
.ready-state p { margin: 0 0 28px; color: var(--muted); font-size: 1.05rem; line-height: 1.65; }

.count-in-state {
  display: grid;
  width: 100%;
  place-items: center;
}

.count-in-state span {
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: clamp(9rem, 28vw, 22rem);
  font-style: italic;
  line-height: 1;
  opacity: 0;
}

.count-in-state span.is-animating {
  animation: countPop 820ms cubic-bezier(.15,.75,.2,1) both;
}

.question-state { width: 100%; animation: questionIn 420ms cubic-bezier(.2,.85,.25,1) both; }
.eyebrow { margin: 0 0 14px; color: var(--accent); font-size: 0.88rem; font-weight: 800; letter-spacing: 0.12em; }

.question-state h2 {
  max-width: 1100px;
  margin: 0 auto 28px;
  font-size: clamp(2.2rem, 4.8vw, 5.4rem);
  line-height: 1.3;
}

.timer { display: grid; gap: 12px; width: min(430px, 100%); margin: 0 auto; }
.timer span { font-family: Impact, "Arial Narrow", sans-serif; font-size: clamp(3.6rem, 7vw, 6.8rem); font-style: italic; color: var(--accent); }
.timer-track { height: 6px; overflow: hidden; border-radius: 999px; background: var(--line); opacity: .52; }
.timer-progress { height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.time-up { margin: 20px 0 0; color: #a1443f; font-size: 1.6rem; font-weight: 900; animation: timeUpPulse 620ms ease both; }

.answer-buttons {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 26px;
}

.answer-button {
  min-width: 150px;
  min-height: 48px;
  border-radius: 10px;
  color: #fff;
  padding: 0 22px;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 900;
  transition: transform 150ms ease, filter 150ms ease;
}

.answer-button:hover { filter: brightness(1.08); transform: translateY(-2px); }
.answer-button:active { transform: translateY(0) scale(.98); }
.correct-button { border: 1px solid #3f744e; background: #3f744e; }
.wrong-button { border: 1px solid #a54843; background: #a54843; }

.result-state { position: relative; width: 100%; text-align: center; animation: resultIn 620ms cubic-bezier(.18,.88,.25,1.12) both; }
.result-state img { width: min(420px, 88%); max-height: 310px; object-fit: contain; border-radius: 14px; }
.result-emoji { font-size: clamp(5rem, 13vw, 9rem); line-height: 1; animation: resultIcon 720ms cubic-bezier(.18,.9,.28,1.25) both; }
.result-state h2 { margin: 24px 0 8px; font-size: clamp(3rem, 7vw, 6.8rem); font-style: italic; }
.result-state p { margin: 0; color: var(--muted); font-size: clamp(1.15rem, 2.2vw, 2rem); font-weight: 700; }
.outcome-success .result-state h2 { color: #356344; }
.outcome-failure .result-state h2 { color: #9c413b; }
.outcome-failure .result-state { animation: resultIn 420ms ease both, failureShake 520ms 280ms ease both; }

.result-burst {
  position: absolute;
  top: 31%;
  left: 50%;
  width: 10px;
  height: 10px;
  pointer-events: none;
}

.result-burst i {
  position: absolute;
  width: 9px;
  height: 34px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0;
}

.outcome-success .result-burst i { animation: burstRay 900ms 160ms ease-out both; }
.result-burst i:nth-child(1) { --ray: 0deg; background: #e5a93e; }
.result-burst i:nth-child(2) { --ray: 45deg; background: #da6b68; }
.result-burst i:nth-child(3) { --ray: 90deg; background: #5689cf; }
.result-burst i:nth-child(4) { --ray: 135deg; background: #63a76a; }
.result-burst i:nth-child(5) { --ray: 180deg; background: #e5a93e; }
.result-burst i:nth-child(6) { --ray: 225deg; background: #da6b68; }
.result-burst i:nth-child(7) { --ray: 270deg; background: #5689cf; }
.result-burst i:nth-child(8) { --ray: 315deg; background: #63a76a; }

@keyframes countPop {
  0% { opacity: 0; transform: scale(.42); filter: blur(8px); }
  24% { opacity: 1; transform: scale(1); filter: blur(0); }
  78% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.14); }
}

@keyframes questionIn {
  from { opacity: 0; transform: translateY(20px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes resultIn {
  from { opacity: 0; transform: translateY(26px) scale(.88); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes resultIcon {
  0% { opacity: 0; transform: rotate(-14deg) scale(.35); }
  70% { opacity: 1; transform: rotate(5deg) scale(1.13); }
  100% { opacity: 1; transform: rotate(0) scale(1); }
}

@keyframes burstRay {
  0% { opacity: 0; transform: rotate(var(--ray)) translateY(-20px) scaleY(.2); }
  35% { opacity: 1; }
  100% { opacity: 0; transform: rotate(var(--ray)) translateY(-150px) scaleY(1); }
}

@keyframes successWash {
  from { background: var(--bg); }
}

@keyframes failureWash {
  0% { background: var(--bg); }
  25% { background: #f0c8c4; }
  100% { background: color-mix(in srgb, #f5dedb 88%, var(--bg)); }
}

@keyframes failureShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-18px) rotate(-1deg); }
  40% { transform: translateX(16px) rotate(1deg); }
  60% { transform: translateX(-10px); }
  80% { transform: translateX(8px); }
}

@keyframes timeUpPulse {
  0% { opacity: 0; transform: scale(.6); }
  55% { opacity: 1; transform: scale(1.18); }
  100% { opacity: 1; transform: scale(1); }
}

.primary-button, .secondary-button, .back-button {
  min-height: 48px;
  border-radius: 10px;
  padding: 0 24px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #fff; font-size: 1.05rem; }
.primary-button:hover { filter: brightness(1.06); }
.secondary-button, .back-button { border: 1px solid var(--line); background: transparent; }
.secondary-button:hover, .back-button:hover { background: var(--surface-hover); }
.back-button {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  margin: 0;
  transform: translateX(-50%);
}
.back-button:hover { transform: translateX(-50%) translateY(-1px); }

.modal {
  position: relative;
  width: min(580px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: clamp(28px, 5vw, 48px);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.modal, .category-title { color: var(--surface-text, var(--text)); }

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.5rem;
}

.modal-kicker { margin: 0 0 8px; color: var(--accent); font-size: 0.78rem; font-weight: 900; letter-spacing: 0.14em; }
.modal h2 { margin: 0 0 24px; font-size: 2rem; }
.modal ol { margin: 0 0 30px; padding-left: 22px; }
.modal li, .modal > p { font-size: 1rem; line-height: 1.7; }
.modal li + li { margin-top: 9px; }

.form-message { min-height: 26px; margin: 0 0 12px !important; color: var(--accent); font-weight: 700; }

.settings-backdrop { place-items: stretch center; overflow-y: auto; padding: 24px; }

.settings-modal {
  width: min(1120px, 100%);
  max-height: none;
  overflow: visible;
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.settings-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 24px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-header h2 { margin: 0; }
.settings-header .modal-close { position: static; flex: 0 0 auto; }

.settings-section {
  margin-bottom: 14px;
  padding: clamp(24px, 4vw, 38px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--surface-text, var(--text));
}

.settings-section h3 { margin: 0 0 22px; font-size: 1.55rem; }
.settings-section h4 { margin: 0 0 12px; font-size: 1rem; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.section-heading h3 { margin-bottom: 6px; }
.section-heading p { margin: 0 0 20px; color: var(--muted); line-height: 1.6; }

.category-editor { display: grid; gap: 10px; margin: 5px 0 18px; }
.category-edit-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; }
.category-number { color: var(--muted); font-family: Georgia, serif; font-style: italic; text-align: center; }
.category-name-input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.remove-category-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  color: #b45353;
  font-size: 1.25rem;
}

.management-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.file-button { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.settings-notes { margin: 20px 0 10px; padding-left: 22px; color: var(--muted); line-height: 1.75; }
.compact-button { min-height: 42px; padding: 0 16px; }

.timer-setting-row {
  display: grid;
  grid-template-columns: auto minmax(130px, 190px) auto;
  align-items: center;
  justify-content: start;
  gap: 14px;
}

.timer-setting-row > label { color: var(--muted); font-weight: 800; }
.duration-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}
.duration-input input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 800;
}
.duration-input span { color: var(--muted); font-weight: 800; }

.color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px; margin-bottom: 22px; }
.color-grid label { display: grid; gap: 10px; color: var(--muted); font-weight: 800; }
.color-grid input[type="color"] { width: 100%; height: 74px; border: 1px solid var(--line); border-radius: 10px; padding: 5px; background: var(--bg); cursor: pointer; }

.image-note { margin: -10px 0 24px !important; color: var(--muted); }
.image-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 30px; }
.image-setting { min-width: 0; }
.image-preview { display: grid; place-items: center; width: 100%; height: 180px; margin-bottom: 12px; overflow: hidden; border: 1px dashed var(--line); border-radius: 12px; background: var(--bg); }
.image-preview span { font-size: 4rem; }
.image-preview img { width: 100%; height: 100%; object-fit: contain; }
.image-setting .file-button { width: calc(100% - 74px); }
.text-button { width: 64px; min-height: 48px; border: 0; background: transparent; color: var(--muted); cursor: pointer; text-decoration: underline; }

.settings-footer { display: flex; justify-content: flex-end; padding: 20px 0 4px; }

@media (max-width: 1080px) {
  .site-header { grid-template-columns: 1fr auto; }
  .site-header h1 { grid-column: 1 / -1; grid-row: 1; }
  .header-actions { grid-column: 1; grid-row: 2; }
  .date-block { grid-column: 2; grid-row: 2; }
  .board { grid-template-columns: repeat(var(--tablet-columns, 3), minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .site-header { padding: 18px 14px 14px; gap: 14px; }
  .site-header h1 { font-size: clamp(2rem, 11vw, 3.2rem); }
  .upload-button { padding: 0 11px; }
  main { padding: 0 14px; }
  .board { grid-template-columns: repeat(var(--mobile-columns, 2), minmax(0, 1fr)); gap: 10px; }
  .category-title { min-height: 58px; font-size: 1rem; }
  .cards { gap: 8px; }
  .score-card { min-height: 112px; font-size: 2rem; }
  .date-block time { font-size: 1rem; }
  .date-block span { font-size: 0.75rem; }
  .game-panel { min-height: calc(100vh - 28px); padding: 28px 20px; }
  .overlay, .modal-backdrop { padding: 14px; }
  .overlay { padding: 0; }
  .game-panel { min-height: 100vh; }
  .settings-backdrop { padding: 10px; }
  .settings-header { padding: 18px 20px; border-radius: 12px; }
  .settings-section { padding: 22px 18px; border-radius: 12px; }
  .section-heading { display: block; }
  .color-grid, .image-grid { grid-template-columns: 1fr; gap: 18px; }
  .management-actions > * { width: 100%; }
  .timer-setting-row { grid-template-columns: 1fr; }
  .timer-setting-row .primary-button { width: 100%; }
  .answer-buttons { gap: 10px; }
  .answer-button { min-width: min(140px, 42vw); padding: 0 16px; }
}

@media (max-width: 420px) {
  .site-header { grid-template-columns: 1fr; }
  .header-actions { grid-column: 1; justify-content: center; }
  .date-block { display: none; }
  .board { grid-template-columns: 1fr; }
  .score-card { min-height: 96px; }
}

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