:root {
  --cw: 52px;
  --ch: 57px;
  --ink: #2b1d10;
  --red: #c0392b;
  --haru: #e86a92;
  --yuu: #3a8fd6;
  --accent: #e86a92;
  --paper: #fffaf0;
  --ui-font: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Yu Gothic UI', 'Meiryo', sans-serif;
  --koma-font: 'Yuji Syuku', 'HG正楷書体-PRO', 'HGSeikaishotaiPRO', 'HG行書体', 'Yu Mincho', 'YuMincho', 'Hiragino Mincho ProN', serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui-font);
  color: var(--ink);
  /* たたみ */
  background-color: #b8b47a;
  background-image:
    repeating-linear-gradient(90deg, rgba(90, 90, 30, .10) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(0deg, rgba(255, 255, 220, .06) 0 2px, transparent 2px 5px),
    linear-gradient(180deg, #c6c28a, #a9a466);
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; cursor: pointer; }
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== ホーム ===== */
#screen-home {
  flex-direction: column; justify-content: center; align-items: center;
  min-height: 100vh; min-height: 100dvh; padding: 10px 16px; box-sizing: border-box;
}
#screen-home.active { display: flex; }
.title {
  font-family: 'Kaisei Decol', var(--koma-font);
  font-size: min(clamp(28px, 5vw, 50px), 6dvh);
  margin: 0 0 4px;
  color: #3b2410;
  text-shadow: 0 2px 0 #fff6d8, 0 4px 10px rgba(0, 0, 0, .25);
  letter-spacing: .08em;
}
.title-sub { display: block; font-size: .45em; letter-spacing: .3em; color: #6b4a22; }
.title-lead { font-size: min(20px, 3dvh); font-weight: 700; margin: 0 0 16px; color: #4a3518; }
.gates { display: flex; justify-content: center; gap: min(4vw, 40px); flex-wrap: wrap; width: 100%; }
.gate {
  border: none; background: var(--paper); border-radius: 22px; padding: clamp(10px, 1.5dvh, 16px);
  width: min(360px, 44vw, 36dvh);
  box-shadow: 0 8px 0 rgba(0, 0, 0, .15), 0 12px 24px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
.gate:hover { transform: translateY(-4px) rotate(-.5deg); }
.gate:active { transform: translateY(2px); }
.gate[data-player="haru"] { --pc: var(--haru); }
.gate[data-player="yuu"] { --pc: var(--yuu); }
.gate-img { position: relative; border-radius: 12px; overflow: hidden; container-type: inline-size; }
.gate-img img { width: 100%; display: block; }
.gate-plaque {
  position: absolute; left: 38.5%; width: 23.5%; top: 38.8%; height: 6.4%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--koma-font); font-weight: 700; color: #2a1606;
  font-size: 5.2cqw; letter-spacing: 0.02em; white-space: nowrap;
}
.gate-info { margin-top: 8px; }
.gate-name { font-size: min(26px, 4dvh); font-weight: 900; color: var(--pc); }
.rank-chip {
  display: inline-block; background: #3b2410; color: #ffe9a8; border-radius: 999px;
  padding: 2px 12px; font-weight: 900; font-size: min(16px, 2.5dvh); margin: 2px 0;
}
.gate-stats { font-size: min(14px, 2dvh); color: #5a4630; }
.parent-link { margin-top: 20px; background: rgba(255, 255, 255, .5); border: 1px solid rgba(0, 0, 0, .15); border-radius: 999px; padding: 8px 18px; font-size: 14px; color: #4a3518; }

/* ===== 共通トップバー ===== */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: rgba(255, 250, 240, .92); box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
  position: sticky; top: 0; z-index: 20;
}
.btn-back { border: none; background: #6b4a22; color: #fff; font-weight: 700; border-radius: 12px; padding: 9px 14px; font-size: 16px; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.pill { border: 2px solid #6b4a22; background: #fff; color: #6b4a22; font-weight: 700; border-radius: 999px; padding: 7px 14px; font-size: 15px; }
.pill:disabled { opacity: .4; }
.player-badge { font-weight: 900; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.player-badge .pname { color: var(--accent); font-size: 24px; }

/* ===== ステージ地図 ===== */
#screen-map { padding-bottom: 50px; }
.map-status { max-width: 900px; margin: 14px auto 0; padding: 0 14px; display: flex; gap: 12px; flex-wrap: wrap; }
.status-card { flex: 1 1 200px; background: var(--paper); border-radius: 16px; padding: 12px 16px; box-shadow: 0 4px 0 rgba(0, 0, 0, .12); }
.status-card h4 { margin: 0 0 6px; font-size: 14px; color: #8a6a40; }
.status-big { font-size: 26px; font-weight: 900; }
.bar { height: 14px; background: #eadfc8; border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #ffb347, #ff7b54); border-radius: 99px; transition: width .6s; }
.stages { max-width: 900px; margin: 16px auto; padding: 0 14px; display: flex; flex-direction: column; gap: 16px; }
.stage {
  background: var(--paper); border-radius: 20px; padding: 14px 16px 16px; position: relative;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .13);
}
.stage.locked { opacity: .55; filter: grayscale(.7); }
.stage-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.stage-no { background: #3b2410; color: #ffe9a8; border-radius: 10px; padding: 2px 10px; font-weight: 900; font-size: 14px; }
.stage-kind { font-size: 13px; font-weight: 700; color: #fff; background: #8a6a40; border-radius: 6px; padding: 1px 8px; }
.stage-kind.k3 { background: #d0782a; }
.stage-kind.k5 { background: #b03030; }
.stage-title { font-size: 22px; font-weight: 900; }
.stage-sub { width: 100%; font-size: 14px; color: #7a5d3a; margin-top: 2px; }
.stage-prog { margin-left: auto; font-weight: 900; color: #8a6a40; }
.stage-master { position: absolute; right: 14px; top: -10px; background: #f4c430; color: #5a3a00; font-weight: 900; border-radius: 999px; padding: 3px 12px; font-size: 13px; box-shadow: 0 3px 0 rgba(0, 0, 0, .2); transform: rotate(4deg); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 9px; margin-top: 12px; }
.tile {
  border: none; border-radius: 12px; height: 66px; font-size: 22px; font-weight: 900;
  background: linear-gradient(#fff, #f3e6cc); color: #5a4026;
  box-shadow: 0 4px 0 #c9b38a; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9b38a; }
.tile .st { font-size: 12px; letter-spacing: -1px; color: #f0a500; height: 14px; }
.tile.clear { background: linear-gradient(#fff6c8, #ffd970); box-shadow: 0 4px 0 #d4a72c; }
.tile.next { animation: pulse 1.4s infinite; background: linear-gradient(#fff, #ffe0ea); box-shadow: 0 4px 0 var(--accent); }
.tile.lock { color: #b9a888; background: #efe6d4; box-shadow: 0 4px 0 #d5c7aa; cursor: default; }
@keyframes pulse { 50% { transform: scale(1.07); } }

/* ===== 問題画面 ===== */
.play-title { font-weight: 900; font-size: 18px; line-height: 1.2; }
.play-title small { display: block; font-size: 13px; color: #8a6a40; font-weight: 700; }
.play-area { display: flex; justify-content: center; align-items: flex-start; gap: 20px; padding: 14px 10px 30px; flex-wrap: wrap; }
.board-wrap { display: flex; align-items: stretch; gap: calc(var(--cw) * .28); }
.komadai {
  width: calc(var(--cw) * 2.3); height: calc(var(--ch) * 3.6);
  background: url(../img/board.jpg) center / 300% auto;
  filter: sepia(.25) saturate(1.1) brightness(.82);
  border-radius: 4px; position: relative; padding: 6px;
  box-shadow: inset 0 0 0 2px rgba(60, 30, 0, .25), 0 calc(var(--cw) * .12) 0 #6e4416, 0 calc(var(--cw) * .2) 18px rgba(0, 0, 0, .45);
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px;
}
.komadai-gote { align-self: flex-start; }
.komadai-sente { align-self: flex-end; align-content: flex-end; flex-direction: row-reverse; flex-wrap: wrap-reverse; }
.komadai-label { position: absolute; font-size: 12px; font-weight: 700; color: #fff8e0; text-shadow: 0 1px 2px #000; white-space: nowrap; }
.komadai-gote .komadai-label { bottom: -24px; left: 0; color: #3b2410; text-shadow: none; }
.komadai-sente .komadai-label { top: -22px; right: 0; color: #3b2410; text-shadow: none; }
.komadai-gote .rest { margin: auto; text-align: center; font-family: var(--koma-font); color: #2a1606; font-size: calc(var(--cw) * .32); line-height: 1.6; filter: none; }
.hand-piece { position: relative; width: calc(var(--cw) * 1.0); height: calc(var(--ch) * 1.0); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.hand-piece .cnt {
  position: absolute; right: -4px; bottom: 0; background: #2b1d10; color: #fff; border-radius: 99px;
  font-size: calc(var(--cw) * .26); min-width: 1.5em; text-align: center; font-weight: 900; padding: 0 3px;
}
.hand-piece.sel .koma { transform: translateY(-6px) scale(1.06); filter: drop-shadow(0 8px 6px rgba(0, 0, 0, .45)) drop-shadow(0 0 6px #ffe066); }

.ban {
  position: relative;
  padding: calc(var(--cw) * .42) calc(var(--cw) * .38);
  background: url(../img/board.jpg) center / cover;
  border-radius: 3px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .25),
    inset 0 0 40px rgba(120, 70, 10, .25),
    0 calc(var(--cw) * .5) 0 #a8701e,
    0 calc(var(--cw) * .5 + 1px) 0 #6e4410,
    0 calc(var(--cw) * .5) 40px rgba(0, 0, 0, .55);
  margin-bottom: calc(var(--cw) * .5);
  margin-top: calc(var(--cw) * .45);
  margin-right: calc(var(--cw) * .45);
}
/* 盤の厚み（側面の木目） */
.ban::after {
  content: ''; position: absolute; left: 0; right: 0; top: 100%; height: calc(var(--cw) * .5);
  background: url(../img/board.jpg) center / 100% 900%;
  filter: brightness(.78) saturate(1.2);
  border-radius: 0 0 3px 3px;
  box-shadow: inset 0 6px 8px rgba(0, 0, 0, .25);
}
.ban-face { position: relative; }
.grid { position: relative; width: calc(var(--cw) * 9); height: calc(var(--ch) * 9); }
.grid svg.lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cell { position: absolute; width: var(--cw); height: var(--ch); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cell.last::before { content: ''; position: absolute; inset: 2px; background: rgba(170, 90, 0, .18); }
.cell.mark-x::after, .cell.mark-o::after, .cell.mark-k::after, .cell.mark-esc::after, .cell.mark-hint::after {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 5;
}
.cell.mark-x::after { content: '×'; color: rgba(210, 30, 30, .85); font-size: calc(var(--cw) * .9); font-weight: 900; text-shadow: 0 0 4px #fff; }
.cell.mark-o::after { content: ''; border: 3px dashed rgba(90, 90, 90, .6); border-radius: 8px; inset: 4px; }
.cell.mark-k::after { content: ''; border: 4px solid rgba(255, 170, 0, .95); border-radius: 8px; inset: 2px; box-shadow: 0 0 12px rgba(255, 170, 0, .9); }
.cell.mark-esc::after { content: '!'; background: rgba(40, 140, 255, .28); border: 3px solid rgba(40, 120, 255, .9); border-radius: 50%; inset: 6px; color: #1a5ec0; font-size: calc(var(--cw) * .5); font-weight: 900; }
.cell.mark-hint::after { content: ''; border: 4px dashed #ff8a00; border-radius: 50%; inset: 4px; animation: pulse 1s infinite; }
.cell.hl-by .koma { filter: drop-shadow(0 0 7px #2b8cff) drop-shadow(0 0 3px #2b8cff); }
.cell.hl-sq::before { content: ''; position: absolute; inset: 1px; background: rgba(255, 60, 60, .28); z-index: 1; }
.coords-top { position: absolute; top: calc(var(--cw) * -.78); left: 0; width: calc(var(--cw) * 9); display: flex; }
.coords-top span { width: var(--cw); text-align: center; font-weight: 700; color: #3b2410; font-size: calc(var(--cw) * .3); }
.coords-right { position: absolute; right: calc(var(--cw) * -.85); top: 0; height: calc(var(--ch) * 9); display: flex; flex-direction: column; }
.coords-right span { height: var(--ch); display: flex; align-items: center; font-weight: 700; color: #3b2410; font-size: calc(var(--cw) * .3); font-family: var(--koma-font); }

/* 駒 */
.koma { display: block; transition: transform .12s, filter .12s; filter: drop-shadow(1px 2px 1.5px rgba(40, 20, 0, .55)); overflow: visible; }
.koma text { font-family: var(--koma-font); font-weight: 700; }
.cell.sel .koma { transform: translateY(-5px) scale(1.06); filter: drop-shadow(0 8px 6px rgba(0, 0, 0, .45)) drop-shadow(0 0 6px #ffe066); }
.koma.placed { animation: pachi .22s ease-out; }
@keyframes pachi {
  0% { transform: translateY(-14px) scale(1.18); filter: drop-shadow(0 14px 10px rgba(0, 0, 0, .35)); }
  70% { transform: translateY(0) scale(.97); }
  100% { transform: none; }
}
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* サイドパネル */
.side { width: min(400px, 96vw); display: flex; flex-direction: column; gap: 12px; }
.sensei { display: flex; gap: 10px; align-items: flex-start; }
.sensei-face { width: 76px; flex: none; }
.sensei-face svg { width: 100%; }
.sensei-face.bounce { animation: bounce .6s; }
@keyframes bounce { 30% { transform: translateY(-14px) rotate(-6deg); } 60% { transform: translateY(0) rotate(4deg); } }
.bubble {
  position: relative; background: #fff; border-radius: 16px; padding: 12px 14px; font-size: 18px; font-weight: 700; line-height: 1.55;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .12); flex: 1; min-height: 64px;
}
.bubble::before { content: ''; position: absolute; left: -10px; top: 22px; border: 8px solid transparent; border-right: 12px solid #fff; border-left: 0; }
.bubble .big { font-size: 26px; font-weight: 900; color: var(--red); }
.bubble .good { color: #e07b00; }
.explain { background: var(--paper); border-radius: 16px; padding: 12px 14px; font-size: 16px; line-height: 1.6; box-shadow: 0 4px 0 rgba(0, 0, 0, .12); display: none; }
.explain.show { display: block; animation: fadeIn .3s; }
.explain h3 { margin: 0 0 6px; font-size: 18px; }
.explain ul { margin: 0; padding: 0; list-style: none; }
.explain li { padding: 6px 8px; border-radius: 10px; margin: 3px 0; background: #fff; border: 1px solid #eadfc8; cursor: pointer; }
.explain li:hover, .explain li.on { background: #fff3c4; border-color: #f0c040; }
.explain li .ic { display: inline-block; width: 1.6em; text-align: center; font-weight: 900; }
.explain .point { background: #fff1f1; border-left: 5px solid var(--red); padding: 8px 10px; border-radius: 6px; margin: 8px 0 0; font-weight: 700; }
.explain .moves { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.explain .mv { border: 2px solid #c9b38a; background: #fff; border-radius: 10px; padding: 4px 10px; font-weight: 900; font-size: 16px; }
.explain .mv.on { background: #3b2410; color: #ffe9a8; border-color: #3b2410; }
.explain .alt { font-size: 14px; color: #5a4630; margin-top: 4px; }
.side-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-main {
  flex: 1 1 140px; border: none; border-radius: 16px; padding: 14px 10px; font-size: 19px; font-weight: 900; color: #fff;
  background: linear-gradient(#ff9a5a, #f0663a); box-shadow: 0 5px 0 #b8441e;
}
.btn-main.blue { background: linear-gradient(#5ab0ff, #2f7fd8); box-shadow: 0 5px 0 #1d5aa0; }
.btn-main.gray { background: linear-gradient(#b6a68c, #8d7c62); box-shadow: 0 5px 0 #6a5a40; }
.btn-main:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.stars-row { font-size: 44px; text-align: center; letter-spacing: 6px; height: 56px; }
.stars-row span { display: inline-block; color: #ddd; text-shadow: 0 2px 0 rgba(0, 0, 0, .15); }
.stars-row span.on { color: #ffc400; animation: starPop .5s both; }
@keyframes starPop { 0% { transform: scale(0) rotate(-180deg); } 70% { transform: scale(1.4); } 100% { transform: scale(1); } }
.thinking { color: #8a6a40; font-size: 15px; }

/* 成り選択 */
.promo { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0, 0, 0, .35); z-index: 60; }
.promo.show { display: flex; }
.promo-box { background: var(--paper); border-radius: 20px; padding: 16px 20px; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .4); }
.promo-box h3 { margin: 0 0 10px; }
.promo-choices { display: flex; gap: 18px; }
.promo-choices button { border: 3px solid #c9b38a; background: #fff; border-radius: 16px; padding: 10px 16px; font-size: 18px; font-weight: 900; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.promo-choices button:hover { border-color: var(--red); }

/* つみ！スタンプ */
.stamp-fx { position: fixed; inset: 0; pointer-events: none; display: flex; align-items: center; justify-content: center; z-index: 70; }
.stamp-fx .s {
  font-family: var(--koma-font); font-size: min(26vw, 220px); color: #d42020; font-weight: 900;
  border: 12px solid #d42020; border-radius: 30px; padding: 0 30px; background: rgba(255, 255, 255, .85);
  transform: rotate(-12deg); animation: stampIn .5s cubic-bezier(.2, 1.6, .4, 1) both, stampOut .4s 1.3s forwards;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .1);
}
@keyframes stampIn { 0% { transform: scale(3) rotate(-12deg); opacity: 0; } 100% { transform: scale(1) rotate(-12deg); opacity: 1; } }
@keyframes stampOut { to { opacity: 0; transform: scale(.9) rotate(-12deg); } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 65; width: 100vw; height: 100vh; }

/* モーダル */
.modal { position: fixed; inset: 0; background: rgba(30, 20, 5, .55); display: none; align-items: center; justify-content: center; z-index: 80; padding: 16px; }
.modal.show { display: flex; animation: fadeIn .25s; }
.modal-box { background: var(--paper); border-radius: 22px; padding: 20px; max-width: 640px; width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 16px 50px rgba(0, 0, 0, .45); }
.modal-box h2 { margin: 0 0 12px; text-align: center; }
.modal-close { display: block; margin: 16px auto 0; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.badge { background: #fff; border-radius: 14px; padding: 10px; text-align: center; border: 2px solid #eadfc8; }
.badge .bi { font-size: 38px; }
.badge .bn { font-weight: 900; font-size: 14px; }
.badge .bd { font-size: 11px; color: #8a6a40; }
.badge.off { opacity: .4; filter: grayscale(1); }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal div { aspect-ratio: 1; background: #fff; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; border: 1px solid #eadfc8; position: relative; }
.cal .wd { background: none; border: none; aspect-ratio: auto; color: #8a6a40; font-size: 13px; }
.cal .on { background: #fff3c4; }
.cal .on::after { content: '🌸'; position: absolute; font-size: 24px; opacity: .9; }
.cal .gold::after { content: '💮'; }
.cal .today { outline: 3px solid var(--accent); }

/* 免状（昇級） */
.menjo {
  background: #fdf6e3 url(../img/koma.jpg) center / cover; border: 10px double #8b1a1a; border-radius: 6px; padding: 26px 20px;
  text-align: center; font-family: var(--koma-font); color: #2a1606; position: relative;
}
.menjo .m1 { font-size: 22px; letter-spacing: .4em; }
.menjo .m2 { font-size: 64px; font-weight: 900; color: #8b1a1a; margin: 6px 0; }
.menjo .m3 { font-size: 20px; line-height: 1.8; }
.menjo .hanko { position: absolute; right: 22px; bottom: 18px; width: 70px; height: 70px; border: 4px solid #d42020; color: #d42020; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; line-height: 1.05; transform: rotate(8deg); font-weight: 900; }
.parent table { width: 100%; border-collapse: collapse; font-size: 15px; }
.parent td, .parent th { border-bottom: 1px solid #eadfc8; padding: 6px; text-align: left; }
.parent .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.parent .danger { background: #fff; border: 2px solid #c0392b; color: #c0392b; border-radius: 10px; padding: 8px 12px; font-weight: 700; }
.parent p { font-size: 14px; line-height: 1.7; }

@media (max-width: 760px) {
  .play-area { padding-top: 6px; }
  .topbar .pill { padding: 6px 10px; font-size: 13px; }
  .play-title { font-size: 15px; }
}
