* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f1ece1;
  --panel: #faf7f0;
  --panel2: #f3eee3;
  --line: #d8d0bf;
  --ink: #2d2a24;
  --muted: #857d6d;
  --red: #b5432c;
  --paper: #fdfcf8;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.hidden { display: none !important; }

.screen { position: fixed; inset: 0; overflow-y: auto; }

/* ========== 首頁 ========== */
.home-inner { max-width: 860px; margin: 0 auto; padding: 56px 24px 48px; }
.home-head h1 {
  font-family: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  font-size: 2.3rem; letter-spacing: 0.22em; font-weight: 700;
  display: flex; align-items: center; gap: 14px;
}
.seal {
  font-family: "Noto Serif TC", "Songti TC", serif;
  background: var(--red); color: #fdf8ef;
  font-size: 1.05rem; letter-spacing: 0;
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px; transform: rotate(-3deg);
}
.home-head .sub { color: var(--muted); margin: 14px 0 34px; line-height: 1.8; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 640px) { .cards { grid-template-columns: 1fr; } }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 20px 22px; cursor: pointer; text-align: left;
  color: var(--ink); font: inherit;
  box-shadow: 2px 3px 0 rgba(45, 42, 36, 0.05);
  transition: border-color .12s, box-shadow .12s;
}
.card:hover { border-color: var(--red); box-shadow: 2px 3px 0 rgba(181, 67, 44, 0.15); }
.card:nth-child(even) { transform: rotate(0.2deg); }
.card:nth-child(odd) { transform: rotate(-0.2deg); }
.card .card-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.card .num {
  font-family: "Noto Serif TC", "Songti TC", serif;
  color: var(--red); font-size: 1.05rem; font-weight: 700;
}
.card h2 {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 1.2rem; letter-spacing: 0.06em;
}
.card .best { margin-left: auto; color: var(--red); font-size: .82rem; }
.card p { color: var(--muted); font-size: .9rem; line-height: 1.7; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 30px; line-height: 1.9; }

/* ========== 遊戲頁骨架 ========== */
#play { display: flex; flex-direction: column; overflow: hidden; }
.play-head {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; border-bottom: 1px solid var(--line); flex: none;
  background: var(--panel);
}
.head-mid { display: flex; align-items: baseline; gap: 12px; flex: 1; min-width: 0; }
#playTitle { font-family: "Noto Serif TC", "Songti TC", serif; font-weight: 700; letter-spacing: 0.05em; }
#stepDots { color: var(--muted); letter-spacing: .2em; font-size: .8rem; }
.head-right { display: flex; align-items: center; gap: 12px; }
.timer { font-variant-numeric: tabular-nums; color: var(--red); font-weight: 700; }

.play-main { display: flex; gap: 14px; padding: 14px 16px; flex: 1; min-height: 0; }
.side { width: 292px; flex: none; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.canvas-area { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }

#canvasWrap { position: relative; }
#paper {
  position: absolute; inset: 0; background: var(--paper); border-radius: 2px;
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(45, 42, 36, 0.14);
}
#canvasWrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 2px; }
#paintCanvas { touch-action: none; cursor: crosshair; }
#guideCanvas, #diffCanvas { pointer-events: none; }

/* ========== 側欄面板 ========== */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
.panel-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .82rem; color: var(--muted); margin-bottom: 8px; letter-spacing: 0.08em;
}
.target-panel canvas { width: 100%; border-radius: 2px; display: block; background: var(--paper); border: 1px solid var(--line); }
.instruction { font-size: .92rem; line-height: 1.75; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.side-actions { justify-content: space-between; }

.step-nav { margin-top: 8px; flex-wrap: nowrap; }
.step-nav .tool-btn { padding: 5px 10px; flex: none; }
.step-label { flex: 1; font-size: .8rem; color: var(--ink); line-height: 1.45; }

.light-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--red); font-size: .8rem; }
#lightArrow { display: inline-block; transition: transform .15s; }

.slider-row { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); margin: 6px 0; }
.slider-row input[type=range] { flex: 1; accent-color: var(--red); }
.slider-row select {
  flex: 1; background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: 4px; padding: 4px; font: inherit;
}
.slider-val { width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* ========== 工具列 ========== */
.toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); flex: none;
  background: var(--panel);
}
.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-label { color: var(--muted); font-size: .8rem; }

.tool-btn, .ghost-btn {
  background: var(--paper); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 12px; font: inherit; font-size: .88rem; cursor: pointer;
}
.tool-btn:active { transform: scale(.96); }
.tool-btn.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tool-btn.disabled { opacity: .35; pointer-events: none; }
.ghost-btn { background: transparent; border: none; color: var(--muted); }

.primary-btn {
  margin-left: auto;
  background: var(--red); color: #fdf8ef; border: none; border-radius: 6px;
  padding: 10px 24px; font: inherit; font-weight: 700; font-size: 1rem; cursor: pointer;
  letter-spacing: 0.1em;
  box-shadow: 2px 2px 0 rgba(45, 42, 36, 0.18);
}
.primary-btn:active { transform: scale(.97); }

input[type=range] { accent-color: var(--red); }
.size-group input { width: 110px; }
#sizeDot { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; }
#sizeDot i { display: block; background: #6d675c; border-radius: 50%; }

.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer;
}
.swatch.active { border-color: var(--red); box-shadow: 0 0 0 2px rgba(181, 67, 44, 0.3); }
.swatch.disabled { opacity: .25; pointer-events: none; }

.mini-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.mini-toggle input { accent-color: var(--red); }

/* ========== 結果面板 ========== */
.result {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.result-card {
  pointer-events: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 22px; max-width: 560px; width: 100%;
  box-shadow: 0 12px 40px rgba(45, 42, 36, 0.22);
  animation: slideUp .22s ease-out;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } }
.result-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 6px; }
.result-score {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 2rem; font-weight: 800; color: var(--red);
}
.result-stars { font-size: 1.2rem; letter-spacing: .1em; color: var(--red); }
.result-tips { color: var(--muted); font-size: .9rem; line-height: 1.7; margin: 8px 0 14px; }
.result-tips li { margin-left: 1.2em; }
.result-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.summary-list { margin: 10px 0 4px; font-size: .92rem; line-height: 2; list-style: none; }
.summary-list .sc { float: right; font-variant-numeric: tabular-nums; color: var(--red); }
.title-chip {
  display: inline-block; background: var(--panel2); border: 1px solid var(--red);
  color: var(--red); border-radius: 999px; padding: 4px 14px; font-size: .9rem; margin: 8px 0 12px;
}

/* ========== 窄螢幕(iPad 直向 / 手機) ========== */
@media (max-width: 860px) {
  .play-main { flex-direction: column; }
  .side { width: 100%; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .side .panel { flex: none; width: 220px; }
  .target-panel { width: 170px !important; }
  .canvas-area { flex: 1; }
}
