:root {
  --bg: #1b2233;
  --panel: #243049;
  --panel-2: #34415f;
  --accent: #ffd166;
  --text: #e8edf7;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #3a3f4b;
  --key-bg: #566180;
  --tile-border: rgba(255, 255, 255, .22);
  --tile-border-filled: rgba(255, 255, 255, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: calc(8px + env(safe-area-inset-top))
           calc(8px + env(safe-area-inset-right))
           calc(8px + env(safe-area-inset-bottom))
           calc(8px + env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 0%, #2a3656, var(--bg));
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

/* ---- 顶栏 ---- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel);
  padding: 8px 12px;
  border-radius: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

h1 {
  margin: 0;
  font-size: clamp(15px, 4.2vw, 24px);
  letter-spacing: 1.5px;
  color: var(--accent);
  font-weight: 800;
  white-space: nowrap;
}

.mode-switch {
  display: flex;
  gap: 3px;
  background: var(--bg);
  padding: 3px;
  border-radius: 10px;
}
.mode-switch button {
  background: transparent;
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  opacity: .6;
  white-space: nowrap;
}
.mode-switch button.active {
  background: var(--panel-2);
  opacity: 1;
}

.actions { display: flex; gap: 6px; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  color: #1b2233;
  background: var(--accent);
  font-family: inherit;
  touch-action: manipulation;
  transition: transform .1s ease, filter .15s ease;
}
button:active { transform: scale(.94); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  padding: 8px 9px;
}
.secondary { background: var(--panel-2); color: var(--text); }

@media (hover: hover) {
  button:hover { filter: brightness(1.12); }
}

/* ---- 棋盘 ---- */
#boardWrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}

#board { display: grid; grid-template-rows: repeat(6, auto); gap: 6px; }
.row { display: grid; grid-template-columns: repeat(5, auto); gap: 6px; }

.row.shake { animation: shake .5s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.row.bounce .tile { animation: bounce .6s ease; }
.row.bounce .tile:nth-child(2) { animation-delay: .08s; }
.row.bounce .tile:nth-child(3) { animation-delay: .16s; }
.row.bounce .tile:nth-child(4) { animation-delay: .24s; }
.row.bounce .tile:nth-child(5) { animation-delay: .32s; }
@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-24px); }
  50% { transform: translateY(4px); }
  60% { transform: translateY(-10px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--tile-border);
  border-radius: 6px;
  font-weight: 800;
  text-transform: uppercase;
  user-select: none;
  -webkit-user-select: none;
  background: transparent;
  transition: transform .25s ease;
}
.tile.filled { border-color: var(--tile-border-filled); animation: popIn .1s ease; }
@keyframes popIn {
  from { transform: scale(.85); }
  to { transform: scale(1); }
}
.tile.flip { transform: rotateX(90deg); }
.tile.correct, .tile.present, .tile.absent { border-color: transparent; color: #fff; }
.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent { background: var(--absent); }

/* ---- 键盘 ---- */
#keyboard {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1;
  max-width: 46px;
  height: clamp(44px, 6.5dvh, 56px);
  border-radius: 6px;
  background: var(--key-bg);
  color: var(--text);
  font-size: clamp(13px, 3.6vw, 16px);
  font-weight: 700;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color .3s ease, filter .15s ease;
}
.key.wide { flex: 1.6; max-width: 74px; font-size: clamp(11px, 3vw, 13px); }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: var(--absent); color: rgba(255, 255, 255, .55); }

/* ---- toast ---- */
#toast {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: #eceff7;
  color: #1b2233;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 30;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---- 弹层 ---- */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 14, 24, .72);
  backdrop-filter: blur(3px);
  z-index: 10;
}
.overlay.show { display: flex; }

.modal {
  background: var(--panel);
  border-radius: 18px;
  padding: 24px 26px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  animation: modalPop .3s ease;
  max-width: min(92vw, 400px);
  width: 100%;
  max-height: 84dvh;
  overflow-y: auto;
  text-align: center;
}
@keyframes modalPop {
  from { transform: scale(.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal h2 { margin: 0 0 14px; font-size: 20px; }
.modal-btns { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

/* 统计 */
.stat-grid { display: flex; justify-content: center; gap: 16px; margin-bottom: 16px; }
.stat-item .num { font-size: 25px; font-weight: 800; color: var(--accent); }
.stat-item .lbl { font-size: 11px; opacity: .7; }
.dist-title { font-size: 13px; opacity: .7; margin: 0 0 8px; font-weight: 600; }
.dist { text-align: left; margin: 0 auto; max-width: 300px; }
.dist-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; }
.dist-bar {
  background: var(--panel-2);
  border-radius: 4px;
  padding: 2px 8px;
  min-width: 24px;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dist-bar.hit { background: var(--correct); color: #fff; }

#answerReveal { margin: 0 0 12px; font-size: 15px; }
#answerReveal .word { letter-spacing: 2px; font-weight: 800; color: var(--accent); }
.countdown { font-size: 13px; opacity: .75; margin: 14px 0 0; font-variant-numeric: tabular-nums; }

/* 帮助 */
.help-body { text-align: left; font-size: 14px; line-height: 1.7; }
.help-body p { margin: 10px 0; }
.demo-cap { margin: 2px 0 0 !important; }
.c-correct { color: var(--correct); }
.c-present { color: var(--present); }
.demo-row { display: flex; gap: 4px; margin: 10px 0 2px; }
.demo-tile {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 800;
  color: #fff;
  border: 2px solid var(--tile-border);
}
.demo-tile.correct { background: var(--correct); border-color: transparent; }
.demo-tile.present { background: var(--present); border-color: transparent; }
.demo-tile.absent { background: var(--absent); border-color: transparent; }

/* 启动错误 */
.boot-error {
  position: fixed;
  inset: auto 12px 12px;
  background: #b3453c;
  color: #fff;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  z-index: 50;
}

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