/* ============================================================
 * 斗兽棋 · 动物大冒险 —— 儿童向视觉样式
 * 原则：暖色纸感底 / 大圆角 / 高对比 / 大字 / 触摸与遥控器都友好
 * ============================================================ */

:root {
  --paper: #FFFBF1;
  --paper-2: #FBF1DA;
  --board-bg: #EADCB8;
  --board-line: #CDB88C;
  --land: #F5E9CD;
  --land-2: #EFE0BC;
  --river: #94D2F0;
  --river-2: #6EBCE6;
  --ink: #4A3826;
  --ink-soft: #7C6A52;
  --red: #C93A2B;
  --red-soft: #FBDDD6;
  --blue: #2E63C6;
  --blue-soft: #D8E6FB;
  --gold: #F5B942;
  --gold-deep: #C98A18;
  --green: #3FA96B;
  --shadow: 0 2px 0 rgba(120, 96, 60, .28);
  --radius: 16px;
  --cell: 40px;
  --font: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, .btn, .icon-btn, .seg-btn { touch-action: manipulation; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: radial-gradient(circle at 50% 0%, #FFFBF1 0%, #FBF1DA 55%, #F3E4C4 100%);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  overflow: hidden;
  overscroll-behavior: none;
}

#app { position: relative; width: 100%; height: 100%; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: 10px 12px 12px; overflow-y: auto; }
.screen.active { display: flex; }
#screen-game { overflow: hidden; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------- 通用按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 17px; font-weight: 700; color: var(--ink);
  background: #FFFDF6; border: 2px solid #E2D2AC; border-radius: 14px;
  padding: 12px 18px; min-height: 52px; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .08s ease, background .15s ease, border-color .15s ease;
  user-select: none;
}
.btn:hover { background: #FFF9E8; border-color: var(--gold); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.btn-primary { background: var(--gold); border-color: var(--gold-deep); color: #4A3406; }
.btn.btn-primary:hover { background: #FFC956; }
.btn.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-soft); font-weight: 600; }
.btn.btn-ghost:hover { background: #F6EBD3; }
.btn.btn-sm { font-size: 15px; padding: 9px 12px; min-height: 46px; }
.btn[disabled] { opacity: .45; cursor: default; box-shadow: none; transform: none; }
.btn-ico { display: inline-flex; width: 22px; height: 22px; }
.icon { width: 100%; height: 100%; display: block; }

.icon-btn {
  width: 48px; height: 48px; min-height: 48px; padding: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #FFFDF6; border: 2px solid #E2D2AC; border-radius: 50%;
  box-shadow: var(--shadow); cursor: pointer; color: var(--ink);
}
.icon-btn:hover { border-color: var(--gold); }

/* 遥控器/键盘焦点：必须显眼 */
.ui-btn:focus, input:focus, .cell.cursor { outline: 4px solid #FF9F1C; outline-offset: 2px; }
button:focus-visible { outline: 4px solid #FF9F1C; outline-offset: 2px; }

/* ---------------- 首页 ---------------- */
.home-top { display: flex; align-items: center; justify-content: space-between; }
.home-top-right { display: flex; gap: 8px; }
.guard-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #FFF3D2; border: 2px solid #F0D28A; border-radius: 999px;
  padding: 6px 12px; font-size: 15px; font-weight: 700; color: #7A5A10;
}
.guard-chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.guard-chip.warn { background: #FFE7E2; border-color: #F0A79B; color: #94301F; }
.guard-chip.warn .dot { background: var(--red); }
.guard-chip.small { font-size: 14px; padding: 4px 10px; }

.hero { text-align: center; margin: 6px 0 2px; }
.hero h1 {
  margin: 4px 0 0; font-size: 34px; letter-spacing: 2px; line-height: 1.15;
  color: #8A3A12;
}
.hero h1 em {
  display: block; font-style: normal; font-size: 16px; letter-spacing: 6px;
  color: var(--ink-soft); font-weight: 600; margin-top: 2px;
}
.hero-art { display: flex; justify-content: center; align-items: flex-end; gap: 2px; height: 116px; margin-top: 4px; }
.hero-art .mascot-svg { width: 104px; height: 104px; }
.hero-art .hero-piece { width: 56px; height: 56px; margin-bottom: 6px; }
.hero-art .hero-piece:nth-child(2) { transform: rotate(-10deg); }
.hero-art .hero-piece:nth-child(3) { transform: rotate(6deg); }
.hero-sub { margin: 6px 12px 0; font-size: 15px; color: var(--ink-soft); font-weight: 600; }

.menu { display: flex; flex-direction: column; gap: 10px; margin: 12px auto 0; width: min(420px, 100%); }
.seg { display: flex; background: #FFF6E2; border: 2px solid #E9D9B4; border-radius: 14px; padding: 4px; gap: 4px; }
.seg-btn {
  flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 10px 0;
  font-family: inherit; font-size: 15px; font-weight: 700; color: var(--ink-soft); cursor: pointer;
}
.seg-btn.active { background: #FFFDF6; color: var(--red); box-shadow: 0 1px 0 rgba(120, 96, 60, .2); }
.home-foot { text-align: center; font-size: 14px; color: var(--ink-soft); margin: 14px 0 0; font-weight: 600; }
.home-note { text-align: center; font-size: 12.5px; color: #A08E72; margin: 8px 14px 0; line-height: 1.6; }

/* ---------------- 对局 ---------------- */
.topbar { display: flex; align-items: center; gap: 8px; }
.turn-chip {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: #FFFDF6; border: 2px solid #E9D9B4; border-radius: 999px;
  padding: 8px 14px; font-weight: 700; font-size: 16px; min-height: 46px;
}
.turn-chip.is-red { border-color: #E9A79C; background: #FFF1EE; color: #A02818; }
.turn-chip.is-blue { border-color: #A8C1EE; background: #EFF5FF; color: #1E4A9C; }
.turn-chip.thinking::after { content: "···"; animation: blink 1s steps(4) infinite; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
@keyframes blink { 0%,100% { opacity: .2 } 50% { opacity: 1 } }

.stage { flex: 1; min-height: 0; display: flex; gap: 10px; margin-top: 8px; }
.board-wrap {
  position: relative; flex: 1; min-height: 0; min-width: 0;
  display: flex; align-items: center; justify-content: center;
}
/* 用 flex-wrap 而不是 CSS Grid：连老款电视浏览器也能正确排版 */
.board {
  display: flex; flex-wrap: wrap;
  background: var(--board-bg);
  border: 5px solid #C7A96C; border-radius: 14px;
  box-shadow: 0 4px 0 rgba(120, 96, 60, .28), inset 0 0 0 2px rgba(255, 255, 255, .5);
  overflow: hidden;
}
.cell {
  position: relative; width: var(--cell); height: var(--cell);
  background: var(--land);
  box-shadow: inset 0 0 0 1px rgba(150, 124, 80, .22);
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.cell.alt { background: var(--land-2); }
.cell.river { background: var(--river); box-shadow: inset 0 0 0 1px rgba(46, 110, 150, .22); }
.cell.river::after {
  content: ""; position: absolute; inset: 0;
  background:
    repeating-linear-gradient(115deg, rgba(255,255,255,.34) 0 5px, transparent 5px 13px);
  pointer-events: none;
}
.cell.den { background: #F0DFAE; }
.cell.den-blue { box-shadow: inset 0 0 0 3px var(--blue); }
.cell.den-red { box-shadow: inset 0 0 0 3px var(--red); }
.cell.trap { background: #F7E7C8; }
.cell.trap-blue::before, .cell.trap-red::before {
  content: ""; position: absolute; inset: 3px; border: 2px dashed currentColor; border-radius: 8px;
  pointer-events: none; opacity: .85;
}
.cell.trap-blue::before { color: var(--blue); }
.cell.trap-red::before { color: var(--red); }
.mark {
  position: absolute; font-size: calc(var(--cell) * .42); font-weight: 700; opacity: .5;
  pointer-events: none; letter-spacing: 0; color: var(--ink-soft);
}
.mark.den-blue { color: var(--blue); opacity: .75; }
.mark.den-red { color: var(--red); opacity: .75; }
.mark.trap-blue { color: var(--blue); }
.mark.trap-red { color: var(--red); }

.piece {
  position: relative; z-index: 2;
  width: calc(var(--cell) - 4px); height: calc(var(--cell) - 4px);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  filter: drop-shadow(0 2px 1px rgba(90, 70, 40, .3));
  transition: transform .16s ease;
  will-change: transform;
}
.piece-svg { width: 100%; height: 100%; display: block; }
.piece.side-red { animation: none; }
.cell.sel .piece { transform: scale(1.12) translateY(-3px); }
.cell.sel { background: #FFE9B8 !important; }
.cell.cursor::after {
  content: ""; position: absolute; inset: 1px; border: 3px solid #FF9F1C; border-radius: 10px;
  pointer-events: none; z-index: 3;
}
.cell.target::before {
  content: ""; position: absolute; width: 34%; height: 34%; border-radius: 50%;
  background: rgba(63, 169, 107, .85); box-shadow: 0 0 0 3px rgba(255, 255, 255, .6);
  z-index: 4; pointer-events: none;
}
.cell.target-eat::before {
  content: "×"; position: absolute; font-size: calc(var(--cell) * .62); font-weight: 700; line-height: 1;
  color: #fff; text-shadow: 0 0 0 #C93A2B;
  background: rgba(201, 58, 43, .92); border-radius: 50%;
  width: 62%; height: 62%; display: flex; align-items: center; justify-content: center;
  z-index: 4; pointer-events: none; animation: pop .5s ease-in-out infinite alternate;
}
@keyframes pop { from { transform: scale(.9) } to { transform: scale(1.06) } }
.cell.last-from { background: #DCEBFF !important; }
.cell.last-to { background: #FFE7A8 !important; }
.cell.flash { animation: flashCell .45s ease-out; }
@keyframes flashCell { from { background: #FFD86B } to { background: transparent } }
.cell.pulse::after {
  content: ""; position: absolute; inset: 0; border: 3px solid #FF9F1C; border-radius: 12px;
  animation: pulse 1.1s ease-in-out infinite; pointer-events: none; z-index: 3;
}
@keyframes pulse { 0%,100% { opacity: .25; transform: scale(.94) } 50% { opacity: 1; transform: scale(1) } }
.cell.shake { animation: shakeCell .3s; }
@keyframes shakeCell { 25% { transform: translateX(-3px) } 75% { transform: translateX(3px) } }
.cell.hint-from { box-shadow: inset 0 0 0 3px #3FA96B; }
.cell.hint-to { box-shadow: inset 0 0 0 3px #3FA96B; animation: pulse 1.1s ease-in-out infinite; }

.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.burst { position: absolute; width: 0; height: 0; }
.burst i {
  position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%;
  background: var(--gold); animation: burst .55s ease-out forwards;
}
.burst i:nth-child(1) { --a: 0deg } .burst i:nth-child(2) { --a: 60deg }
.burst i:nth-child(3) { --a: 120deg } .burst i:nth-child(4) { --a: 180deg }
.burst i:nth-child(5) { --a: 240deg } .burst i:nth-child(6) { --a: 300deg }
@keyframes burst { from { transform: rotate(var(--a)) translateX(2px) scale(1); opacity: 1 }
  to { transform: rotate(var(--a)) translateX(26px) scale(.2); opacity: 0 } }

/* 侧栏 */
.side { width: 250px; flex: 0 0 250px; display: flex; flex-direction: column; gap: 8px; }
.side-hint {
  display: flex; gap: 8px; align-items: flex-start;
  background: #FFFDF6; border: 2px solid #E9D9B4; border-radius: 14px; padding: 10px 12px;
  font-size: 14.5px; line-height: 1.55; font-weight: 600; min-height: 62px;
}
.side-hint-ico { width: 20px; height: 20px; flex: 0 0 20px; color: var(--blue); }

/* 困局守护提示条：棋局僵住时出现，招呼小朋友看提示 */
.help-chip {
  display: flex; gap: 8px; align-items: flex-start;
  background: #FFF6DC; border: 2px solid #F3D68F; border-radius: 14px; padding: 9px 12px;
  font-size: 14px; line-height: 1.5; font-weight: 700; color: #8A6420;
  box-shadow: 0 2px 0 rgba(190, 158, 92, .28);
  animation: pop .22s ease-out;
}
.help-chip[hidden] { display: none; }
.hc-ico { width: 20px; height: 20px; flex: 0 0 20px; color: var(--gold-deep); }
/* 提示按钮发光：告诉小朋友「这里可以点」 */
.btn.glow { animation: glowPulse 1.3s ease-in-out infinite; }
@keyframes glowPulse {
  0%, 100% { box-shadow: var(--shadow); border-color: #E2D2AC; }
  50% { box-shadow: 0 0 0 5px rgba(255, 196, 92, .55), var(--shadow); border-color: var(--gold); }
}
.side-actions { display: flex; gap: 8px; }
.side-actions .btn { flex: 1; }
.legend { background: #FFF9EA; border: 2px dashed #E4D2A8; border-radius: 14px; padding: 10px 12px; font-size: 13px; color: var(--ink-soft); line-height: 1.9; }
.legend-row { display: flex; align-items: center; gap: 7px; }
.lg-dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: 0 0 14px; }
.lg-dot.flag-red { background: var(--red-soft); border: 2px solid var(--red); }
.lg-dot.flag-blue { background: var(--blue-soft); border: 2px solid var(--blue); }
.lg-dot.wave { background: var(--river); border: 2px solid var(--river-2); }
.lg-dot.trap-red { background: #F7E7C8; border: 2px dashed var(--red); }
.lg-dot.den-blue { background: #F0DFAE; border: 2px solid var(--blue); }
.keyhint { margin-top: auto; font-size: 12.5px; color: #A08E72; line-height: 1.7; background: #FFF9EA; border-radius: 12px; padding: 8px 10px; }

/* 引导面板 */
.coach {
  display: flex; gap: 10px; align-items: flex-start;
  background: #FFFDF3; border: 3px solid var(--gold); border-radius: var(--radius);
  box-shadow: 0 -2px 0 rgba(120, 96, 60, .18); padding: 10px 12px; margin-top: 8px;
}
.coach[hidden] { display: none; }
.coach-mascot { width: 62px; height: 62px; flex: 0 0 62px; }
.coach-mascot .mascot-svg { width: 100%; height: 100%; animation: bob 1.8s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-4px) } }
.coach-main { flex: 1; min-width: 0; }
.coach-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.coach-step { font-size: 12.5px; font-weight: 700; color: #8A6A12; background: #FFEFC2; border-radius: 999px; padding: 3px 9px; }
.coach-title { font-size: 16px; font-weight: 700; color: #8A3A12; }
.coach-say { margin: 6px 0 0; font-size: 15px; line-height: 1.65; }
.coach-body { margin-top: 8px; }
.coach-actions { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; }
.coach-actions .btn { min-width: 112px; }

.ladder { display: flex; align-items: center; gap: 4px; overflow-x: auto; padding: 4px 2px 6px; }
.ladder-item { text-align: center; flex: 0 0 auto; }
.ladder-art { width: 46px; height: 46px; }
.ladder-art .mini-svg { width: 100%; height: 100%; }
.ladder-name { font-size: 12px; font-weight: 700; color: var(--ink); }
.ladder-name span { display: block; font-size: 10.5px; color: #A08E72; }
.ladder-gt { font-size: 16px; font-weight: 700; color: var(--gold-deep); flex: 0 0 auto; }
.ladder-note { font-size: 13px; color: #94301F; background: #FFEDE9; border-radius: 10px; padding: 6px 10px; }

/* ---------------- 休息 ---------------- */
#screen-rest { align-items: center; justify-content: center; }
.rest-card {
  width: min(520px, 100%); background: #FFFDF6; border: 4px solid #F0D28A; border-radius: 22px;
  padding: 20px; text-align: center; box-shadow: 0 6px 0 rgba(120, 96, 60, .2);
}
.rest-mascot { width: 96px; height: 96px; margin: 0 auto 4px; }
.rest-mascot .mascot-svg { width: 100%; height: 100%; }
.rest-card h2 { margin: 4px 0 6px; font-size: 26px; color: #8A3A12; }
.rest-sub { margin: 0 0 12px; color: var(--ink-soft); font-weight: 600; }
.rest-clock { font-size: 54px; font-weight: 700; letter-spacing: 3px; color: var(--red); }
.rest-bar { height: 12px; background: #F1E4C8; border-radius: 999px; overflow: hidden; margin: 10px 0 14px; }
.rest-bar i { display: block; height: 100%; width: 100%; background: var(--gold); transition: width 1s linear; }
.rest-tips { text-align: left; margin: 0 0 16px; padding-left: 18px; color: var(--ink-soft); line-height: 1.9; font-size: 14.5px; }
.rest-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------------- 设置 ---------------- */
#screen-settings { align-items: center; justify-content: flex-start; overflow: auto; }
.settings-card { width: min(520px, 100%); background: #FFFDF6; border: 3px solid #E9D9B4; border-radius: 20px; padding: 18px; margin: auto; }
.settings-card h2 { margin: 0 0 14px; font-size: 22px; color: #8A3A12; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px dashed #EEE0C4; font-size: 15.5px; font-weight: 600; }
.field input[type="number"] { width: 110px; min-height: 46px; font-size: 17px; font-weight: 700; text-align: center; border: 2px solid #E2D2AC; border-radius: 12px; background: #FFFDF6; font-family: inherit; }
.field.switch input { width: 26px; height: 26px; accent-color: var(--gold-deep); }
.settings-note { font-size: 13px; color: var(--ink-soft); line-height: 1.6; margin: 12px 0; }
.settings-actions { display: flex; flex-direction: column; gap: 9px; }

/* ---------------- 弹窗 ---------------- */
.modal { position: fixed; inset: 0; background: rgba(74, 56, 38, .45); display: flex; align-items: center; justify-content: center; padding: 18px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { width: min(420px, 100%); background: #FFFDF6; border: 4px solid var(--gold); border-radius: 22px; padding: 20px; text-align: center; box-shadow: 0 8px 0 rgba(120, 96, 60, .22); }
.modal-card h3 { margin: 6px 0 8px; font-size: 24px; color: #8A3A12; }
.modal-card p { margin: 0 0 14px; color: var(--ink-soft); font-weight: 600; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result-badge { width: 96px; height: 96px; margin: 0 auto; }
.result-badge .mascot-svg { width: 100%; height: 100%; }
.gate-q { font-size: 26px !important; font-weight: 700 !important; color: var(--ink) !important; }
#gate-input { width: 160px; min-height: 52px; font-size: 20px; text-align: center; border: 2px solid #E2D2AC; border-radius: 12px; font-family: inherit; }
.gate-err { color: var(--red) !important; font-size: 14px; min-height: 20px; margin: 8px 0 10px !important; }

/* ---------------- 横屏 / 电视大屏 ---------------- */
@media (orientation: landscape) and (min-width: 860px) {
  .stage { flex-direction: row; }
  .side { width: 280px; flex: 0 0 280px; }
}
@media (orientation: portrait) {
  .stage { flex-direction: column; }
  .side { width: 100%; flex: 0 0 auto; flex-direction: row; flex-wrap: wrap; }
  .help-chip { flex: 1 1 100%; }
  .side-hint { flex: 1 1 100%; }
  .side-actions { flex: 1 1 100%; }
  .legend { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 4px 14px; }
  .keyhint { display: none; }
}
/* 引导局中隐藏图例，把纵向空间让给棋盘 */
#screen-game.tut .legend { display: none; }

/* 矮屏（小手机 / 横屏手机）：压缩首页与侧栏，保证棋盘优先 */
@media (max-height: 720px) {
  .hero-art { height: 76px; }
  .hero-art .mascot-svg { width: 76px; height: 76px; }
  .hero-art .hero-piece { width: 42px; height: 42px; }
  .hero h1 { font-size: 26px; }
  .hero h1 em { font-size: 14px; letter-spacing: 4px; }
  .legend { display: none; }
  .btn { min-height: 46px; padding: 10px 16px; font-size: 16px; }
  .side-hint { min-height: 0; font-size: 13.5px; }
}

/* 电视遥控器模式：字体放大、光标更显眼 */
body.tv-mode { font-size: 18px; }
body.tv-mode .cell.cursor::after { border-width: 4px; border-color: #FF6B00; }
body.tv-mode .btn { font-size: 19px; }
body.tv-mode .side { width: 320px; flex: 0 0 320px; }
@media (min-width: 1400px) {
  body.tv-mode .turn-chip { font-size: 20px; }
  body.tv-mode .side-hint { font-size: 17px; }
}
