:root {
  --bg: #2b2420;
  --bg2: #352c26;
  --card: #f4ead8;
  --card2: #e9dcc4;
  --ink: #2a211b;
  --soft: #7a6a5c;
  --wood: #e7c48a;
  --wood-dark: #b98a4e;
  --head: #c8352a;
  --head-dark: #8e2018;
  --gold: #e8a33a;
  --green: #5aa84a;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #3d332c 0, var(--bg) 70%) fixed;
  color: var(--card);
  user-select: none;
}
#app { max-width: 560px; margin: 0 auto; padding: 0 14px 24px; }
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* buttons */
.btn {
  font: inherit; font-weight: 700; font-size: 15px; border: 0; cursor: pointer;
  padding: 10px 18px; border-radius: 12px; background: var(--card); color: var(--ink);
  box-shadow: 0 3px 0 #a99474; transition: transform .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #a99474; }
.btn-red { background: linear-gradient(#df5040, var(--head)); color: #fff; box-shadow: 0 3px 0 var(--head-dark); }
.btn-gold { background: linear-gradient(#f3bd5a, var(--gold)); box-shadow: 0 3px 0 #a86f1c; }
.btn[disabled] { opacity: .45; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--bg2); color: var(--card);
  font-size: 24px; cursor: pointer;
}
.link-btn { background: none; border: 0; color: #cdbba3; font: inherit; font-size: 14px; cursor: pointer; padding: 6px; }
.link-btn[disabled] { visibility: hidden; }

/* hub */
.hub-head { text-align: center; padding: 34px 0 18px; }
.box-logo {
  display: inline-block; padding: 14px 34px; border-radius: 10px;
  background: linear-gradient(90deg, #8e2018 0 12px, var(--head) 12px calc(100% - 12px), #8e2018 calc(100% - 12px));
  box-shadow: 0 6px 0 #5a140f, 0 10px 24px rgba(0,0,0,.4);
  transform: rotate(-2deg);
}
.box-logo span { font-size: 40px; font-weight: 900; letter-spacing: 6px; color: #fff3d6; text-shadow: 0 2px 0 #5a140f; }
.sub { color: #cdbba3; margin: 16px 0 0; }
.channels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.channel {
  background: var(--card); color: var(--ink); border-radius: 16px; padding: 14px; cursor: pointer; text-align: left;
  border: 0; font: inherit; box-shadow: 0 4px 0 #a99474; display: flex; flex-direction: column; gap: 6px; min-height: 120px;
}
.channel:active { transform: translateY(2px); }
.channel .ch-icon { height: 46px; }
.channel b { font-size: 18px; }
.channel small { color: var(--soft); font-size: 12px; line-height: 1.4; }
.channel .ch-prog { margin-top: auto; font-size: 12px; color: var(--soft); }
.channel .ch-bar { height: 5px; border-radius: 3px; background: var(--card2); overflow: hidden; }
.channel .ch-bar i { display: block; height: 100%; background: var(--green); }

/* bars */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 0 6px; }
.bar h2 { margin: 0; font-size: 20px; }
.bar-title { text-align: center; }
.bar-title h2 { font-size: 19px; }
.bar-title p { margin: 2px 0 0; font-size: 12px; color: #cdbba3; }
.bar-right { min-width: 40px; text-align: right; color: #cdbba3; font-size: 14px; }

/* level list */
.list-desc { color: #cdbba3; font-size: 13px; margin: 0 0 12px; }
.level-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.level-cell {
  aspect-ratio: 1; border-radius: 10px; border: 0; background: var(--bg2); color: #cdbba3;
  font: inherit; font-weight: 700; cursor: pointer; position: relative;
}
.level-cell.done { background: #4c6b3c; color: #fff; }
.level-cell .tag { position: absolute; left: 0; right: 0; bottom: 2px; font-size: 9px; font-weight: 400; opacity: .8; }
.list-section { grid-column: 1 / -1; color: #cdbba3; font-size: 13px; margin-top: 8px; }

/* play */
.prompt { background: var(--card); color: var(--ink); border-radius: 12px; padding: 10px 14px; font-size: 16px; font-weight: 700; margin: 6px 0 10px; line-height: 1.5; }
.board-wrap { position: relative; }
.board {
  width: 100%; display: block; background: #3a2f28; border-radius: 16px; touch-action: none;
  box-shadow: inset 0 0 0 2px #4a3d34, inset 0 10px 30px rgba(0,0,0,.25);
}
.ghost { stroke: rgba(244,234,216,.18); stroke-width: .05; stroke-dasharray: .12 .1; stroke-linecap: round; }
.match .shaft { fill: var(--wood); stroke: var(--wood-dark); stroke-width: .015; }
.match .head { fill: var(--head); stroke: var(--head-dark); stroke-width: .015; }
.match.held { opacity: .35; }
.match.preview { opacity: .55; }
.match.hint { animation: hintBlink 1.6s ease infinite; }
.slot-hint { stroke: var(--gold); stroke-width: .12; stroke-linecap: round; opacity: .8; animation: hintBlink 1.6s ease infinite; }
@keyframes hintBlink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.shape-fill { opacity: 0; animation: shapeIn .5s ease forwards; }
@keyframes shapeIn { to { opacity: .55; } }
.item { fill: #d8263a; stroke: #7a1020; stroke-width: .03; }
.item-stem { stroke: #4f7a2c; stroke-width: .05; fill: none; }

.toast {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9); opacity: 0; pointer-events: none;
  background: rgba(20,15,12,.9); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 16px; transition: .2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.good { background: rgba(70,140,55,.95); }
.actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.actions.minor { justify-content: space-between; margin-top: 4px; }

.found { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 10px; font-size: 14px; color: #cdbba3; }
.found .chip { width: 36px; height: 36px; border-radius: 8px; background: var(--bg2); display: grid; place-items: center; font-size: 22px; color: var(--card); }
.found .chip.empty { color: #6a5a4e; }

.numpad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 14px; }
.numpad .num-display { grid-column: 1 / -1; text-align: center; font-size: 30px; font-weight: 800; background: var(--card); color: var(--ink); border-radius: 12px; padding: 6px; min-height: 52px; }
.numpad .btn { padding: 12px 0; font-size: 20px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 10; padding: 20px; }
.modal-card { background: var(--card); color: var(--ink); border-radius: 20px; padding: 22px; width: 100%; max-width: 380px; text-align: center; border: 3px solid var(--gold); animation: pop .35s ease; }
.modal-card h3 { margin: 0 0 8px; font-size: 24px; color: var(--head); }
.modal-card p { margin: 0 0 16px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* nim */
.nim-setup { display: grid; gap: 10px; }
.nim-game-btn { text-align: left; }
.nim-game-btn b { display: block; font-size: 17px; }
.nim-game-btn small { color: var(--soft); font-weight: 400; }
.nim-opts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: #cdbba3; font-size: 14px; }
.nim-opts .btn { padding: 7px 12px; font-size: 14px; }
.nim-opts .btn.on { background: var(--gold); }
.nim-turn { text-align: center; font-size: 18px; font-weight: 800; margin: 4px 0 10px; }
.nim-board .match.sel .shaft { fill: #ffe6a6; }
.nim-board .match.sel { filter: drop-shadow(0 0 .08px #ffd36b); }
.nim-board .match.gone { opacity: 0; transition: opacity .5s; }

/* riddles */
.riddle-list { display: grid; gap: 14px; }
.riddle { background: var(--card); color: var(--ink); border-radius: 16px; padding: 14px; }
.riddle h4 { margin: 0 0 6px; font-size: 16px; }
.riddle p { margin: 0 0 10px; line-height: 1.6; }
.riddle svg { width: 100%; max-height: 180px; background: #3a2f28; border-radius: 12px; display: block; }
.riddle .answer { margin-top: 10px; }
.riddle .answer p { color: #5a3d1f; }
