:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --bg-soft: #fffdf8;
  --surface: #ffffff;
  --border: #e2dbcf;
  --text: #24211c;
  --text-soft: #6c6459;
  --accent: #b8372f;
  --accent-soft: #fbe9e6;
  --gold: #b07d23;
  --ok: #2f7a4f;
  --danger: #b3261e;
  --shadow: 0 12px 30px rgba(60, 46, 30, 0.08);
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #171514;
  --bg-soft: #201d1b;
  --surface: #241f1d;
  --border: #3a332f;
  --text: #f2ece5;
  --text-soft: #b5a99c;
  --accent: #ff8a76;
  --accent-soft: #3a2420;
  --gold: #e2b055;
  --ok: #7fd0a2;
  --danger: #ff8f86;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

.shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 16px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(140deg, #d9554b, #8d2233);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  flex: 0 0 auto;
}

.brand-text h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 2px;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-soft);
}

.scoreboard {
  display: flex;
  gap: 10px;
  margin: 0;
}

.stat {
  min-width: 58px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

.stat dt { font-size: 11px; color: var(--text-soft); }
.stat dd { margin: 2px 0 0; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

.notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.5;
}

.board {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  background: var(--bg);
  border-radius: 14px;
}

.mode {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-soft);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.mode.is-active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.current-card {
  border-radius: 16px;
  padding: 16px 14px;
  background: linear-gradient(160deg, var(--accent-soft), transparent 70%);
  border: 1px solid var(--border);
  text-align: center;
}

.card-label { margin: 0; font-size: 12px; color: var(--text-soft); letter-spacing: 1px; }

.current-idiom {
  margin: 6px 0 4px;
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 700;
  letter-spacing: 6px;
  word-break: break-all;
  color: var(--text);
}

.chain-hint { margin: 0; font-size: 13px; color: var(--text-soft); }
.chain-hint span { color: var(--accent); font-weight: 700; font-size: 16px; }

.timer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.timer-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  transition: width 120ms linear;
}

#timer-text {
  font-size: 13px;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

.answer { display: flex; gap: 8px; }

#answer-input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline-offset: 2px;
}

#answer-input:focus { border-color: var(--accent); }

button {
  font-family: inherit;
  cursor: pointer;
}

.primary {
  min-height: 48px;
  padding: 0 20px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.primary:disabled, .mode:disabled, .actions button:disabled { opacity: 0.55; cursor: not-allowed; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.actions button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 14px;
}

.feedback {
  margin: 0;
  min-height: 20px;
  font-size: 14px;
  color: var(--text-soft);
}

.feedback.ok { color: var(--ok); }
.feedback.warn { color: var(--gold); }
.feedback.bad { color: var(--danger); }

.history h2 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text-soft);
  font-weight: 600;
}

.history h2 span { color: var(--text); }

.chain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 168px;
  overflow-y: auto;
}

.chain-list li {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: 14px;
  letter-spacing: 1px;
}

.chain-list li.is-ai { color: var(--text-soft); border-style: dashed; }
.chain-list li.is-player { border-color: var(--accent); }
.chain-list li.is-current { background: var(--accent-soft); border-color: var(--accent); font-weight: 700; }

.rules {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  font-size: 13px;
  color: var(--text-soft);
}

.rules summary { cursor: pointer; min-height: 32px; line-height: 32px; }
.rules ul { margin: 4px 0 0; padding-left: 18px; line-height: 1.7; }

.result {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}

.result h2 { margin: 0 0 6px; font-size: 18px; }
.result p { margin: 0 0 12px; color: var(--text-soft); font-size: 14px; line-height: 1.6; }

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-soft);
}

.linklike {
  min-height: 44px;
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  text-decoration: underline;
}

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

@media (max-width: 360px) {
  .shell { padding: 12px 10px 24px; }
  .brand-mark { width: 34px; height: 34px; font-size: 17px; }
  .brand-text h1 { font-size: 18px; }
  .stat { min-width: 52px; padding: 5px 8px; }
  .board { padding: 12px; }
  .actions button { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .timer-bar { transition: none; }
}
