:root {
  --bg: #f6efe1;
  --bg-strong: #eadbc8;
  --panel: rgba(255, 251, 245, 0.88);
  --panel-strong: rgba(248, 241, 232, 0.96);
  --panel-border: rgba(108, 74, 42, 0.12);
  --ink: #2f2418;
  --muted: #715b43;
  --accent: #b5472f;
  --accent-strong: #87311e;
  --accent-soft: #f7d3b5;
  --gold: #d5b46a;
  --success: #40684f;
  --danger: #8f2e2a;
  --shadow: 0 22px 60px rgba(80, 42, 16, 0.16);
  --cell-size: 58px;
  --cell-font-size: 1.72rem;
  --cell-gap: 3px;
  --cell-radius: 10px;
}

@font-face {
  font-family: "HanYiKai";
  src: url("./assets/fonts/HanYiKaiTiFan-1.ttf") format("truetype");
  font-display: swap;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Kaiti SC", "KaiTi", "STKaiti", "BiauKai", "HanYiKai", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 223, 181, 0.8), transparent 28%),
    radial-gradient(circle at bottom right, rgba(199, 126, 79, 0.22), transparent 25%),
    linear-gradient(145deg, #fbf4e9 0%, #f2e5cf 46%, #ecd8b8 100%);
}

body.script-simplified {
  font-family: "Kaiti SC", "KaiTi", "STKaiti", "PingFang SC", "HanYiKai", serif;
}

body.script-traditional {
  font-family: "HanYiKai", "BiauKai", "KaiTi", "STKaiti", serif;
}

button,
select,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
  appearance: none;
  -webkit-appearance: none;
  text-indent: 0;
}

button:hover {
  transform: translateY(-1px);
}

.app-shell {
  width: min(1580px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 16px 0 24px;
}

.topbar,
.panel,
.dialog-card {
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.top-stats,
.mini-status {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.top-stats::-webkit-scrollbar,
.mini-status::-webkit-scrollbar {
  display: none;
}

.stat-pill,
.stat-chip {
  padding: 6px 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(241, 229, 209, 0.9));
  border: 1px solid rgba(108, 74, 42, 0.08);
  white-space: nowrap;
}

.stat-pill span,
.stat-chip span,
.hint,
.eyebrow {
  color: var(--muted);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.2vw, 2rem);
}

.mobile-menu-btn {
  display: none;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.8rem;
}

.panel {
  padding: 12px;
}

.compact-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.compact-controls {
  display: grid;
  gap: 6px;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 6px;
  align-items: end;
}

.control-row label,
.speech-dialog label {
  display: grid;
  gap: 4px;
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

select,
textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(108, 74, 42, 0.16);
  background: rgba(255, 255, 255, 0.9);
  padding: 9px 11px;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.button-row {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  align-items: center;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.button-row::-webkit-scrollbar {
  display: none;
}

.toolbar-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.dense-row {
  margin-top: 0;
}

.primary,
.secondary,
.ghost,
.file-picker {
  border-radius: 999px;
  padding: 7px 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff8f1;
  box-shadow: 0 10px 22px rgba(181, 71, 47, 0.28);
}

.secondary {
  background: rgba(108, 74, 42, 0.1);
  color: var(--ink);
}

.ghost,
.file-picker {
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink);
  border: 1px solid rgba(108, 74, 42, 0.16);
}

.file-picker {
  position: relative;
  overflow: hidden;
}

.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.compact-picker {
  white-space: nowrap;
  min-width: 42px;
  justify-content: center;
}

.import-card {
  width: min(620px, calc(100vw - 24px));
}

.import-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0 10px;
}

.import-actions .hint {
  margin: 0;
}

.import-dialog textarea {
  min-height: 180px;
}

.font-tools {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-left: 2px;
}

.mini-btn {
  min-width: 36px;
  padding: 7px 9px;
}

.slim-btn {
  background: transparent;
  border-color: rgba(108, 74, 42, 0.12);
  box-shadow: none;
}

.script-toggle {
  display: inline-flex;
  gap: 4px;
  justify-content: flex-start;
  align-items: center;
  padding-top: 18px;
}

.script-toggle .slim-btn {
  min-width: 40px;
}

.script-toggle .active {
  background: rgba(181, 71, 47, 0.12);
  border-color: rgba(181, 71, 47, 0.24);
}

.summary-strip {
  padding: 8px 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 247, 235, 0.95), rgba(241, 229, 209, 0.9));
  line-height: 1.4;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: auto hidden;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  white-space: normal;
  overflow: visible;
}

.score-card {
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.38);
  border: 1px solid rgba(108, 74, 42, 0.08);
}

.score-emoji {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 2px;
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.score-value {
  display: block;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
}

.board-panel {
  min-width: 0;
}

.spacious-board {
  padding: 10px 12px 12px;
  background: var(--panel);
}

.board-header {
  display: block;
  margin-bottom: 4px;
  min-height: 18px;
}

.board {
  display: grid;
  gap: var(--cell-gap);
  justify-content: center;
  align-content: start;
  padding: 6px 2px 2px;
  overflow: auto;
  min-height: 80vh;
  max-height: 84vh;
  touch-action: manipulation;
}

.board-empty {
  margin: 0;
  padding: 18px 20px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 248, 237, 0.96), rgba(240, 227, 204, 0.9));
  color: var(--muted);
  line-height: 1.7;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: var(--cell-radius);
  border: 1px solid rgba(108, 74, 42, 0.12);
  background: linear-gradient(180deg, #fffdfa, #f5e7cf);
  color: var(--ink);
  font-size: var(--cell-font-size);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  vertical-align: middle;
  box-shadow: 0 6px 14px rgba(73, 44, 16, 0.08);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  font-variant-east-asian: normal;
}

.cell:hover {
  box-shadow: 0 12px 24px rgba(73, 44, 16, 0.14);
}

.cell.revealed {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(234, 219, 200, 0.9));
  box-shadow: inset 0 0 0 1px rgba(108, 74, 42, 0.08);
}

.cell.mine {
  background: linear-gradient(180deg, #b5472f, #7f2518);
  color: #fff4ee;
}

.cell.flagged {
  background: linear-gradient(180deg, #fff5d6, #e9cf8d);
  color: var(--ink);
}

.cell.zero {
  color: transparent;
}

.cell.num-1 { color: #3868a6; }
.cell.num-2 { color: #3f7b49; }
.cell.num-3 { color: #a63f38; }
.cell.num-4 { color: #6d4db4; }
.cell.num-5 { color: #93532d; }
.cell.num-6 { color: #19707e; }
.cell.num-7 { color: #5f5140; }
.cell.num-8 { color: #8a8a8a; }

.speech-dialog {
  border: 0;
  background: transparent;
  padding: 0;
}

.speech-dialog::backdrop {
  background: rgba(46, 28, 15, 0.45);
  backdrop-filter: blur(6px);
}

.dialog-card {
  width: min(540px, calc(100vw - 24px));
  max-height: min(86vh, 680px);
  padding: 16px 16px 12px;
  overflow: auto;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.dialog-header h3 {
  margin: 2px 0 0;
  font-size: 1.05rem;
  line-height: 1.3;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(108, 74, 42, 0.08);
  font-size: 1.2rem;
  color: var(--ink);
  flex: 0 0 auto;
}

.target-char-wrap {
  display: grid;
  place-items: center;
  margin: 10px 0 8px;
}

.word-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 10px;
}

.meta-card {
  padding: 8px 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 247, 235, 0.95), rgba(241, 229, 209, 0.9));
  border: 1px solid rgba(108, 74, 42, 0.08);
}

.meta-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.target-char {
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(246, 224, 197, 0.96)),
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.9), transparent 34%);
  font-size: 2.35rem;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(108, 74, 42, 0.08), 0 12px 24px rgba(73, 44, 16, 0.12);
}

.dialog-actions,
.dialog-footer {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 0;
  margin: 0;
}

.dialog-footer {
  justify-content: flex-end;
  margin-top: 10px;
  padding-top: 10px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255, 251, 245, 0.72), rgba(255, 251, 245, 0.98));
  backdrop-filter: blur(6px);
}

.speech-dialog textarea {
  padding: 8px 10px;
  min-height: 78px;
  line-height: 1.4;
}

@media (max-width: 1180px) {
  .topbar,
  .toolbar-row {
    align-items: start;
    flex-direction: column;
  }

  .top-stats,
  .mini-status {
    justify-content: flex-start;
  }

  .control-row {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .board {
    min-height: 74vh;
  }

  .score-strip {
    grid-template-columns: repeat(5, minmax(110px, 1fr));
  }
}

@media (max-width: 640px) {
  :root {
    --cell-size: 42px;
    --cell-font-size: 1.34rem;
    --cell-gap: 1px;
    --cell-radius: 8px;
  }

  .app-shell {
    width: min(100vw - 16px, 100%);
    padding-top: 8px;
  }

  .panel,
  .topbar,
  .dialog-card {
    border-radius: 18px;
  }

  .dialog-card {
    width: min(100vw - 14px, 100%);
    max-height: 88vh;
    padding: 12px 12px 10px;
  }

  .import-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .import-actions .ghost {
    width: 100%;
  }

  .control-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-row,
  .topbar {
    gap: 6px;
  }

  .button-row,
  .mini-status,
  .top-stats {
    width: 100%;
  }

  .score-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .top-stats {
    display: none;
  }

  .mobile-menu-btn {
    display: inline-flex;
    margin-left: auto;
  }

  .compact-controls {
    display: none;
    gap: 10px;
    padding: 10px;
  }

  .compact-controls.is-open {
    display: grid;
  }

  .control-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-row,
  .mini-status {
    flex-direction: column;
    align-items: stretch;
  }

  .button-row,
  .dense-row {
    width: 100%;
  }

  .script-toggle {
    padding-top: 0;
  }

  .button-row > * {
    flex: 0 0 auto;
  }

  .font-tools {
    display: inline-flex;
    margin-left: 0;
    width: auto;
  }

  .mini-btn {
    min-width: 0;
  }

  .mini-status {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .stat-chip {
    justify-content: space-between;
  }

  .score-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .word-meta {
    grid-template-columns: 1fr;
  }

  .target-char {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    font-size: 2rem;
  }

  .speech-dialog textarea {
    min-height: 64px;
  }

  .dialog-footer {
    gap: 6px;
  }

  .dialog-footer > button {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: 8px;
  }

  .spacious-board {
    padding: 6px;
  }

  .board-header {
    min-height: 0;
    margin-bottom: 2px;
  }

  .board {
    min-height: calc(100vh - 148px);
    max-height: none;
    padding-inline: 0;
  }

  body {
    font-family: "Kaiti SC", "KaiTi", "STKaiti", "PingFang SC", "HanYiKai", serif;
  }
}
