:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --bg: #f4f1ea;
  --card: #ffffff;
  --text: #20211f;
  --muted: #6b6b6b;
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sel: #f6f669;
  --last: #cdd26a;
  --check: #ff6b6b;
  --good: #2e7d32;
  --bad: #c62828;
  --border: #e2ddd2;
  --shadow: 0 2px 8px rgba(0,0,0,.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior: none;
}

.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  background: var(--green); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  box-shadow: var(--shadow);
}
.appbar h1 { font-size: 20px; margin: 0; font-weight: 600; }
.iconbtn {
  background: transparent; border: none; color: #fff;
  font-size: 30px; line-height: 1; width: 36px; height: 36px;
  cursor: pointer; padding: 0;
}

main { padding: 16px; max-width: 560px; margin: 0 auto; }

.screen { display: none; animation: fade .2s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }

h2 { font-size: 16px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.home-hero { text-align: center; margin: 24px 0 28px; }
.home-logo { font-size: 84px; line-height: 1; }
.home-sub { color: var(--muted); margin: 6px 0 0; }
.home-menu { display: flex; flex-direction: column; gap: 14px; }
.bigbtn {
  display: flex; align-items: center; gap: 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 20px; font-size: 19px; font-weight: 600; color: var(--text);
  box-shadow: var(--shadow); cursor: pointer; text-align: left;
}
.bigbtn:active { transform: scale(.98); }
.bigbtn-ico { font-size: 26px; width: 32px; text-align: center; }

.optgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.optrow { display: flex; gap: 10px; }
.opt {
  background: var(--card); border: 2px solid var(--border); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; font-size: 16px; color: var(--text);
  display: flex; flex-direction: column; gap: 2px; text-align: left; flex: 1;
}
.opt small { color: var(--muted); font-size: 12px; font-weight: 400; }
.opt.selected { border-color: var(--green); background: #eaf3ea; }
.opt b { font-weight: 600; }

.primary {
  display: block; width: 100%; margin-top: 22px;
  background: var(--green); color: #fff; border: none; border-radius: 12px;
  padding: 16px; font-size: 18px; font-weight: 700; cursor: pointer;
  box-shadow: var(--shadow);
}
.primary:active { background: var(--green-dark); }

.board-wrap { width: 100%; max-width: 92vw; margin: 10px auto; }
.board { width: 100%; }
.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%; aspect-ratio: 1 / 1;
  border-radius: 6px; overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
}
.sq {
  position: relative; display: flex; align-items: center; justify-content: center;
  user-select: none; cursor: pointer;
}
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }
.sq.selected { background: var(--sel) !important; }
.sq.drag-over { box-shadow: inset 0 0 0 4px rgba(46,125,50,.85); }
.sq.last { box-shadow: inset 0 0 0 100px rgba(205,210,106,.45); }
.sq.check { background: radial-gradient(circle, var(--check) 0%, transparent 72%) !important; }

.piece {
  font-size: 8.2vw; line-height: 1;
  pointer-events: none;
}
.board-wrap {  }
@media (min-width: 520px) { .piece { font-size: 44px; } }
.piece-w { color: #ffffff; text-shadow: 0 0 2px #000, 0 1px 2px rgba(0,0,0,.5); -webkit-text-stroke: 1.2px #3a3a3a; }
.piece-b { color: #2b2b2b; text-shadow: 0 0 1px #000, 0 1px 2px rgba(255,255,255,.25); -webkit-text-stroke: .6px #000; }

.drag-ghost {
  position: fixed; left: 0; top: 0; transform: translate(-50%, -55%);
  pointer-events: none; z-index: 70; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.hint-dot {
  position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(20,80,20,.35); pointer-events: none;
}
.hint-capture {
  position: absolute; inset: 6%; border-radius: 50%;
  border: 5px solid rgba(20,80,20,.4); pointer-events: none;
}
.coord {
  position: absolute; font-size: 10px; font-weight: 700; opacity: .65; pointer-events: none;
}
.coord-file { right: 3px; bottom: 1px; }
.coord-rank { left: 2px; top: 1px; }

.clock {
  text-align: center; font-variant-numeric: tabular-nums;
  font-size: 30px; font-weight: 700; padding: 6px; color: var(--muted);
  letter-spacing: 1px;
}
.clock:empty { display: none; }
.clock.active { color: var(--text); background: #e9f3e9; border-radius: 10px; }

.status { text-align: center; font-size: 17px; min-height: 24px; margin: 4px 0 12px; font-weight: 600; }

.game-controls { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; }
.ctrl {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 6px; font-size: 13px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 600;
}
.ctrl:active { background: #efece4; }
.ctrl-ico { font-size: 20px; }
.ctrl.danger { color: var(--bad); }

.lesson-group-title { font-size: 14px; color: var(--green-dark); margin: 18px 0 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.lesson-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 8px; font-size: 16px; cursor: pointer;
  color: var(--text); text-align: left; box-shadow: var(--shadow); font-weight: 600;
}
.lesson-item:active { transform: scale(.99); }
.lesson-check { margin-left: auto; color: var(--green); font-size: 20px; }

.intro { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; }
.intro p { margin: 6px 0; line-height: 1.5; }
.task { font-size: 17px; font-weight: 600; text-align: center; margin: 10px 0 6px; }
.feedback { text-align: center; min-height: 24px; font-size: 16px; font-weight: 700; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback.hint { color: var(--muted); font-weight: 500; }
.lesson-controls { display: flex; gap: 10px; align-items: center; }
.lesson-controls .ctrl { flex-direction: row; }
.lesson-controls .primary { margin-top: 0; flex: 1; }

.toggle { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 10px; font-size: 16px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--green); }
.muted { color: var(--muted); }

.promo-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.promo-box { background: #fff; border-radius: 14px; padding: 12px; display: flex; gap: 8px; box-shadow: var(--shadow); }
.promo-piece { font-size: 48px; width: 64px; height: 64px; border: 1px solid var(--border); border-radius: 10px; background: #f0d9b5; cursor: pointer; line-height: 1; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.modal.open { display: flex; }
.modal-card { background: #fff; border-radius: 16px; padding: 26px 24px; text-align: center; max-width: 360px; width: 100%; box-shadow: var(--shadow); }
.modal-title { font-size: 26px; font-weight: 800; margin-bottom: 6px; }
.modal-detail { color: var(--muted); font-size: 17px; margin-bottom: 20px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.modal-actions .primary { margin-top: 0; }
