:root {
  color-scheme: light;
  --bg: #fff7ea;
  --surface: #ffffff;
  --surface-soft: #fff0d5;
  --text: #2f251f;
  --muted: #725f53;
  --primary: #f07b3f;
  --primary-dark: #c95b28;
  --danger: #b63b42;
  --danger-dark: #8d252e;
  --border: #e8d4bd;
  --shadow: 0 14px 36px rgba(94, 57, 26, 0.13);
  --normal: #f7f0e6;
  --good: #dff4df;
  --bad: #ffe0e3;
  --item: #fff1b7;
  --special: #e6e0ff;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 5% 8%, rgba(255, 207, 123, 0.35), transparent 28%),
    radial-gradient(circle at 95% 3%, rgba(240, 123, 63, 0.16), transparent 24%),
    var(--bg);
}

button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }

.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: 28px; }
.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

.hero-card {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 30px;
  border-radius: 28px;
  background: linear-gradient(135deg, #fff, #ffe1b4);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.hero-oni { font-size: clamp(72px, 9vw, 120px); filter: drop-shadow(0 12px 10px rgba(84, 37, 17, 0.15)); }
.eyebrow { margin: 0 0 6px; color: var(--primary-dark); font-weight: 800; letter-spacing: .08em; font-size: .85rem; }
h1 { margin: 0; font-size: clamp(2rem, 5vw, 4rem); line-height: 1.05; }
h2 { margin: 0 0 14px; font-size: 1.25rem; }
.lead { margin: 14px 0 0; color: var(--muted); font-weight: 700; }

.setup-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr); gap: 20px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 8px 28px rgba(94, 57, 26, 0.08);
  padding: 22px;
}

.field { display: grid; gap: 8px; margin-top: 16px; font-weight: 800; }
.field > span { color: var(--muted); font-size: .92rem; }
select, textarea, input[type="text"] {
  width: 100%;
  border: 1px solid #d9c5af;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fffdf9;
  color: var(--text);
  outline: none;
}
select:focus, textarea:focus, input[type="text"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(240, 123, 63, 0.17); }
textarea { resize: vertical; min-height: 82px; }

.player-inputs { display: grid; gap: 10px; margin-top: 14px; }
.player-input-row { display: grid; grid-template-columns: 36px minmax(120px, 1fr) 116px 52px; align-items: center; gap: 10px; }
.player-icon { min-width: 0; font-size: 1rem; }
.player-number { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; background: var(--surface-soft); }
.player-color { width: 50px; height: 44px; padding: 4px; border: 1px solid #d9c5af; border-radius: 10px; background: #fff; }

.rule-list { display: grid; gap: 14px; }
.rule-list p { margin: 0; line-height: 1.55; }
.rule-list strong { display: inline-grid; place-items: center; width: 34px; height: 34px; margin-right: 8px; border-radius: 10px; background: var(--surface-soft); }
.small-note { margin: 22px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.6; padding: 14px; background: #fff8ec; border-radius: 14px; }

.setup-actions { display: flex; justify-content: center; gap: 12px; margin-top: 24px; }
.button, .icon-button {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 900;
  transition: transform .12s ease, filter .12s ease, opacity .12s ease;
}
.button:hover, .icon-button:hover { filter: brightness(.98); transform: translateY(-1px); }
.button:active, .icon-button:active { transform: translateY(1px) scale(.99); }
.button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.button { padding: 13px 20px; }
.button.primary { color: #fff; background: linear-gradient(180deg, #f68c51, var(--primary)); box-shadow: 0 8px 20px rgba(240, 123, 63, .28); }
.button.secondary { color: var(--text); background: #f3eadf; }
.button.danger { color: #fff; background: linear-gradient(180deg, #ce5960, var(--danger)); }
.button.compact { padding: 9px 13px; border-radius: 11px; font-size: .9rem; }
.icon-button { width: 43px; height: 43px; background: #f3eadf; font-size: 1.2rem; }

.game-header { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 18px; }
.game-header h1 { font-size: clamp(1.8rem, 4vw, 3rem); }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.status-strip { display: grid; grid-template-columns: 1.1fr .65fr 2fr; gap: 12px; margin-bottom: 16px; }
.status-card { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 14px 16px; border: 1px solid var(--border); border-radius: 17px; background: rgba(255,255,255,.92); box-shadow: 0 6px 18px rgba(94,57,26,.07); }
.status-icon { font-size: 1.9rem; }
.status-label { display: block; color: var(--muted); font-size: .8rem; font-weight: 800; }
.status-card strong { display: block; margin-top: 2px; font-size: 1.1rem; overflow-wrap: anywhere; }
.oni-status { background: linear-gradient(135deg, #fff, #ffe4e7); }
.rule-status strong { font-size: .95rem; }
.oni-status .button { margin-left: auto; }

.pause-banner { margin-bottom: 14px; padding: 12px 16px; text-align: center; color: #fff; background: var(--danger); border-radius: 14px; font-weight: 900; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; }
.board-panel { min-width: 0; }
.board-toolbar { display: flex; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.last-event { margin: 0; color: var(--muted); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: flex-end; gap: 8px 12px; color: var(--muted); font-size: .8rem; font-weight: 800; }
.legend span { white-space: nowrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.dot.normal { background: #d8c9b8; }
.dot.good { background: #78b97c; }
.dot.bad { background: #e17078; }
.dot.item { background: #e2ad25; }
.dot.special { background: #8f75d6; }

.board-viewport { overflow: auto; padding: 4px 2px 12px; max-height: 68vh; }
.board { position: relative; display: grid; grid-template-columns: repeat(10, minmax(64px, 1fr)); grid-auto-rows: minmax(72px, auto); gap: 8px; min-width: 720px; }
.cell {
  position: relative;
  min-height: 72px;
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 7px;
  background: var(--normal);
  overflow: hidden;
}
.cell.good { background: var(--good); }
.cell.bad { background: var(--bad); }
.cell.item { background: var(--item); }
.cell.special { background: var(--special); }
.cell.start { background: #e6f4ff; }
.cell.goal { background: linear-gradient(135deg, #fff0a8, #ffd56c); border-color: #e9a91c; }
.cell.ghost-cell { border-color: var(--danger); box-shadow: inset 0 0 0 2px rgba(182,59,66,.12); }
.cell.chased-cell { animation: chasedPulse 1s ease-in-out infinite; }
.cell-number { color: rgba(47,37,31,.56); font-size: .72rem; font-weight: 900; }
.cell-type { position: absolute; top: 6px; right: 7px; font-size: .85rem; }
.tokens { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-top: 8px; }
.player-token { width: 28px; height: 28px; display: grid; place-items: center; color: #fff; border-radius: 50%; font-size: 1rem; font-weight: 900; border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2); }
.ghost-token { font-size: 1.35rem; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.15)); }
.ghost-chaser {
  position: absolute;
  z-index: 20;
  width: 52px;
  height: 52px;
  pointer-events: none;
  transform: translate(-50%, -55%);
  transition: left .72s cubic-bezier(.2,.9,.25,1.08), top .72s cubic-bezier(.2,.9,.25,1.08);
  filter: drop-shadow(0 5px 4px rgba(72,25,16,.28));
}
.ghost-chaser.no-transition { transition: none !important; }
.ghost-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 2.15rem;
  line-height: 1;
  animation: ghostHover .8s ease-in-out infinite alternate;
}
.ghost-smoke {
  position: absolute;
  left: -17px;
  bottom: 1px;
  font-size: 1.15rem;
  opacity: .9;
  transform-origin: center;
  animation: smokePuff .65s ease-in-out infinite alternate;
}
.ghost-chaser.moving-left .ghost-smoke { left: auto; right: -17px; transform: scaleX(-1); }
.ghost-chaser.moving-left .ghost-face { transform: rotate(-9deg); }
.ghost-chaser.moving-right .ghost-face { transform: rotate(9deg); }
.ghost-chaser.is-moving .ghost-face { animation: ghostRun .24s ease-in-out infinite alternate; }
.ghost-target {
  position: absolute;
  top: -12px;
  left: 50%;
  min-width: 38px;
  padding: 2px 6px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #4a2821;
  color: #fff;
  font-size: .62rem;
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  transform: translateX(-50%);
  box-shadow: 0 2px 5px rgba(0,0,0,.18);
}
.ghost-chaser.danger-close .ghost-target { background: var(--danger); animation: dangerBlink .65s ease-in-out infinite alternate; }

@keyframes ghostHover {
  from { translate: 0 -1px; }
  to { translate: 0 3px; }
}
@keyframes ghostRun {
  from { translate: -2px -1px; scale: .96; }
  to { translate: 3px 2px; scale: 1.08; }
}
@keyframes smokePuff {
  from { opacity: .35; scale: .75; }
  to { opacity: 1; scale: 1.08; }
}
@keyframes chasedPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(182,59,66,0); }
  50% { box-shadow: 0 0 0 5px rgba(182,59,66,.22); }
}
@keyframes dangerBlink {
  from { transform: translateX(-50%) scale(.94); }
  to { transform: translateX(-50%) scale(1.08); }
}

.side-panel { display: grid; align-content: start; gap: 18px; }
.position-summary { display: grid; gap: 12px; }
.position-row { display: grid; gap: 5px; }
.position-head { display: flex; justify-content: space-between; gap: 10px; font-size: .88rem; font-weight: 900; }
.progress-track { position: relative; height: 10px; overflow: hidden; background: #f0e5d8; border-radius: 999px; }
.progress-fill { height: 100%; border-radius: inherit; }
.distance-warning { color: var(--danger); }

.event-log { margin: 0; padding-left: 22px; display: grid; gap: 9px; max-height: 270px; overflow: auto; color: var(--muted); font-size: .86rem; line-height: 1.35; }
.event-log li:first-child { color: var(--text); font-weight: 800; }

.players-panel { margin-top: 18px; }
.player-cards { display: grid; grid-template-columns: repeat(5, minmax(190px, 1fr)); gap: 12px; }
.player-card { border: 2px solid var(--player-color); border-radius: 18px; padding: 15px; background: #fffdf9; min-width: 0; }
.player-card.finished { background: #fff9cf; }
.player-card.captured { background: #ffe7e9; }
.player-card-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.player-name-label { min-width: 0; display: flex; align-items: center; gap: 6px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-card-icon { font-size: 1.25rem; line-height: 1; }
.player-position { color: var(--muted); font-size: .83rem; font-weight: 900; }
.dice-result { min-height: 58px; display: grid; place-items: center; margin: 10px 0; border-radius: 14px; background: #f8efe4; font-size: 2rem; font-weight: 900; }
.dice-result.rolling { animation: shake .35s linear infinite; }
@keyframes shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-8deg) scale(1.06); } 75% { transform: rotate(8deg) scale(.98); } }
.player-actions { display: grid; gap: 8px; }
.player-actions .button { width: 100%; padding: 11px 10px; }
.items { display: flex; flex-wrap: wrap; gap: 5px; min-height: 27px; margin-top: 10px; }
.item-chip { border: 0; border-radius: 999px; padding: 5px 8px; background: #efe5d9; cursor: pointer; font-size: .74rem; font-weight: 900; }
.item-chip:hover { background: #e4d6c6; }
.no-items { color: var(--muted); font-size: .75rem; }
.status-pill { display: inline-block; margin-top: 8px; padding: 4px 7px; border-radius: 999px; background: #f0e6dc; color: var(--muted); font-size: .72rem; font-weight: 900; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(44,30,22,.64); backdrop-filter: blur(4px); }
.modal { width: min(520px, 100%); max-height: calc(100vh - 36px); overflow: auto; padding: 28px; text-align: center; border-radius: 24px; background: #fffdf9; box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.modal-emoji { font-size: 4rem; }
.modal h2 { margin-top: 8px; font-size: 1.65rem; }
.modal p { white-space: pre-line; line-height: 1.65; color: var(--muted); font-weight: 700; }
.modal-extra { margin-top: 12px; }
.modal-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

@media (max-width: 1150px) {
  .player-cards { grid-template-columns: repeat(3, minmax(190px, 1fr)); }
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 780px) {
  .player-input-row { grid-template-columns: 32px minmax(100px, 1fr) 100px 46px; gap: 7px; }
  .app-shell { padding: 14px; }
  .hero-card { padding: 22px; border-radius: 22px; }
  .hero-oni { font-size: 64px; }
  .setup-grid, .status-strip, .side-panel { grid-template-columns: 1fr; }
  .game-header, .board-toolbar { align-items: flex-start; flex-direction: column; }
  .header-actions { justify-content: flex-start; }
  .player-cards { grid-template-columns: 1fr 1fr; }
  .board { grid-template-columns: repeat(10, 60px); min-width: 672px; }
  .cell { min-height: 66px; }
}

@media (max-width: 520px) {
  .player-input-row { grid-template-columns: 30px 1fr 82px 42px; }
  .player-icon { font-size: .9rem; padding-left: 6px; padding-right: 4px; }
  .hero-card { align-items: flex-start; gap: 12px; }
  .hero-oni { font-size: 48px; }
  .player-cards { grid-template-columns: 1fr; }
  .setup-actions { flex-direction: column-reverse; }
  .setup-actions .button { width: 100%; }
  .panel { padding: 17px; border-radius: 18px; }
}

/* ===== v0.1.5 visual and usability update ===== */
body.game-running .app-shell {
  padding-bottom: 148px;
}

.hero-oni {
  width: clamp(120px, 13vw, 190px);
  flex: 0 0 auto;
  font-size: 0;
}

.oni-illustration {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 7px 5px rgba(81, 28, 25, .22));
}

.oni-mini { width: 54px; }
.oni-tiny { width: 29px; display: inline-block; vertical-align: middle; }
.oni-modal { width: 132px; margin: 0 auto; }
.oni-runner { width: 94px; }

.oni-run-body { transform-origin: 76px 61px; animation: oniBodyBounce .42s ease-in-out infinite alternate; }
.oni-front-arm, .oni-back-leg { transform-origin: 82px 53px; animation: oniLimbForward .28s ease-in-out infinite alternate; }
.oni-back-arm, .oni-front-leg { transform-origin: 68px 57px; animation: oniLimbBack .28s ease-in-out infinite alternate; }
.oni-dust { animation: oniDust .55s ease-out infinite; transform-origin: center; }

@keyframes oniBodyBounce {
  from { transform: translateY(-1px) rotate(-2deg); }
  to { transform: translateY(3px) rotate(2deg); }
}
@keyframes oniLimbForward {
  from { transform: rotate(-7deg); }
  to { transform: rotate(8deg); }
}
@keyframes oniLimbBack {
  from { transform: rotate(7deg); }
  to { transform: rotate(-9deg); }
}
@keyframes oniDust {
  from { opacity: .25; transform: translateX(8px) scale(.7); }
  to { opacity: .9; transform: translateX(-8px) scale(1.08); }
}

.status-icon:has(.oni-illustration) {
  width: 56px;
  height: 48px;
  display: grid;
  place-items: center;
  overflow: visible;
}

.board-viewport {
  max-height: min(64vh, 660px);
  min-height: 330px;
  padding: 14px 12px 28px;
  scroll-padding: 100px;
  border-radius: 18px;
  background:
    linear-gradient(rgba(255,255,255,.72), rgba(255,255,255,.72)),
    repeating-linear-gradient(45deg, #f6eadb 0 12px, #fff6ea 12px 24px);
  border: 1px solid #ead7c0;
}

.board {
  grid-auto-rows: minmax(76px, auto);
  row-gap: 24px;
  column-gap: 12px;
  padding: 5px 8px 12px;
}

.cell {
  overflow: visible;
  z-index: 2;
  box-shadow: 0 5px 11px rgba(80, 51, 29, .08);
}

.cell::before,
.cell::after {
  content: "";
  position: absolute;
  z-index: -1;
  background: #d7a05e;
  box-shadow: 0 0 0 3px rgba(255,255,255,.78);
}

.cell.route-right::after {
  width: 18px;
  height: 9px;
  right: -17px;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 999px;
}

.cell.route-left::after {
  width: 18px;
  height: 9px;
  left: -17px;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 999px;
}

.cell.route-turn-down::after {
  width: 10px;
  height: 32px;
  left: 50%;
  bottom: -29px;
  transform: translateX(-50%);
  border-radius: 999px;
}

.cell.route-turn-down::before {
  width: 24px;
  height: 24px;
  left: 50%;
  bottom: -30px;
  transform: translateX(-50%);
  border: 6px solid #d7a05e;
  border-top-color: transparent;
  border-left-color: transparent;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
}

.route-arrow {
  position: absolute;
  z-index: 4;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #8b5729;
  color: #fff;
  font-size: .58rem;
  line-height: 1;
  box-shadow: 0 2px 5px rgba(0,0,0,.18);
}
.route-right .route-arrow { right: -20px; top: 50%; transform: translateY(-50%); }
.route-left .route-arrow { left: -20px; top: 50%; transform: translateY(-50%); }
.route-turn-down .route-arrow { left: 50%; bottom: -31px; transform: translateX(-50%); }

.cell.start,
.cell.goal {
  border-width: 3px;
}

.cell-number {
  padding: 2px 5px;
  border-radius: 7px;
  background: rgba(255,255,255,.72);
  color: rgba(47,37,31,.72);
}

.ghost-chaser {
  width: 96px;
  height: 78px;
  transform: translate(-49%, -64%);
  transition: left .78s cubic-bezier(.16,.86,.25,1.08), top .78s cubic-bezier(.16,.86,.25,1.08);
  filter: none;
}

.ghost-art {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.ghost-chaser.moving-left .ghost-art {
  transform: scaleX(-1);
}

.ghost-chaser.is-moving .oni-runner {
  animation: oniChaseHop .18s ease-in-out infinite alternate;
}

.ghost-chaser.danger-close .oni-illustration {
  filter: drop-shadow(0 0 7px rgba(211,34,48,.8)) drop-shadow(0 7px 5px rgba(81,28,25,.25));
}

@keyframes oniChaseHop {
  from { transform: translateY(-2px) rotate(-2deg) scale(.98); }
  to { transform: translateY(4px) rotate(2deg) scale(1.04); }
}

.ghost-target {
  top: -8px;
  min-width: 48px;
  padding: 4px 8px;
  font-size: .7rem;
}

.position-oni {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dice-result {
  min-height: 86px;
  background: linear-gradient(145deg, #f8efe4, #fffaf3);
  perspective: 500px;
}

.die-shell {
  width: 66px;
  height: 66px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  padding: 9px;
  border: 2px solid #d1b99e;
  border-radius: 15px;
  background: linear-gradient(145deg, #ffffff 0%, #f6eadc 72%, #dfcab2 100%);
  box-shadow:
    0 9px 0 #b99b7c,
    0 13px 18px rgba(73, 45, 24, .22),
    inset 4px 4px 8px rgba(255,255,255,.9),
    inset -5px -5px 9px rgba(166,129,92,.16);
  transform: rotateX(4deg) rotateY(-5deg);
  transition: transform .16s ease;
}

.pip {
  width: 11px;
  height: 11px;
  place-self: center;
  border-radius: 50%;
  background: transparent;
}
.pip.on {
  background: radial-gradient(circle at 35% 30%, #5e4a3a 0 22%, #251a14 48% 100%);
  box-shadow: inset 1px 1px 2px rgba(255,255,255,.25), 0 1px 1px rgba(255,255,255,.8);
}

.die-idle .die-shell {
  opacity: .72;
}

.dice-result.rolling .die-shell,
.dock-die.rolling .die-shell {
  animation: diceTumble .24s linear infinite;
}

@keyframes diceTumble {
  0% { transform: rotate(-8deg) rotateX(5deg) scale(.94); }
  45% { transform: rotate(9deg) rotateY(14deg) translateY(-5px) scale(1.06); }
  100% { transform: rotate(-5deg) rotateX(-12deg) translateY(1px) scale(.98); }
}

.roll-hint {
  margin: 4px 0 8px;
  color: var(--muted);
  text-align: center;
  font-size: .76rem;
  font-weight: 800;
}

.dice-dock {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: 0;
  width: min(1500px, 100%);
  min-height: 118px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  transform: translateX(-50%);
  border: 1px solid rgba(195,146,99,.65);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  background: rgba(255,250,243,.94);
  box-shadow: 0 -12px 35px rgba(61,39,21,.2);
  backdrop-filter: blur(14px);
}

.dice-dock-title {
  display: grid;
  justify-items: center;
  gap: 2px;
  color: var(--primary-dark);
  font-weight: 900;
  font-size: .78rem;
}
.dice-dock-title > span:first-child { font-size: 1.55rem; }

.dice-dock-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 9px;
}

.dock-roll-button {
  min-width: 0;
  min-height: 82px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 49px;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 3px solid var(--player-color);
  border-radius: 18px;
  background: linear-gradient(145deg, #fff, color-mix(in srgb, var(--player-color) 11%, #fff));
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--player-color) 60%, #7b563b), 0 8px 12px rgba(0,0,0,.1);
  transition: transform .12s ease, box-shadow .12s ease;
}

.dock-roll-button:hover:not(:disabled) { transform: translateY(-2px); }
.dock-roll-button:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 color-mix(in srgb, var(--player-color) 60%, #7b563b); }
.dock-roll-button:disabled { opacity: .48; cursor: not-allowed; filter: grayscale(.25); }
.dock-roll-button.finished { background: #fff8c8; }
.dock-roll-button.captured { background: #ffe2e5; }

.dock-player-icon {
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--player-color);
  border: 2px solid #fff;
  font-size: 1.45rem;
  box-shadow: 0 2px 7px rgba(0,0,0,.18);
}

.dock-roll-text {
  min-width: 0;
  display: grid;
  text-align: left;
}
.dock-roll-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.dock-roll-text small { color: var(--primary-dark); font-size: .78rem; font-weight: 900; }

.dock-die .die-shell {
  width: 45px;
  height: 45px;
  padding: 6px;
  gap: 2px;
  border-radius: 10px;
  border-width: 1px;
  box-shadow: 0 5px 0 #b99b7c, 0 7px 9px rgba(73,45,24,.18);
}
.dock-die .pip { width: 7px; height: 7px; }

.modal-emoji:has(.oni-illustration) {
  font-size: 0;
}

.kana-mode {
  letter-spacing: .035em;
}
.kana-mode .modal p,
.kana-mode .rule-status strong,
.kana-mode .event-log {
  line-height: 1.85;
}

@media (max-width: 900px) {
  body.game-running .app-shell { padding-bottom: 142px; }
  .dice-dock { grid-template-columns: 1fr; gap: 5px; min-height: 126px; padding-top: 8px; }
  .dice-dock-title { display: none; }
  .dice-dock-buttons {
    display: flex;
    overflow-x: auto;
    gap: 9px;
    padding: 2px 2px 6px;
    scroll-snap-type: x mandatory;
  }
  .dock-roll-button { flex: 0 0 166px; scroll-snap-align: start; }
  .board-viewport { max-height: 55vh; min-height: 300px; }
}

@media (max-width: 520px) {
  body.game-running .app-shell { padding-bottom: 138px; }
  .hero-oni { width: 92px; }
  .board { grid-template-columns: repeat(10, 64px); min-width: 724px; }
  .board-viewport { max-height: 49vh; min-height: 280px; }
  .ghost-chaser { width: 82px; height: 69px; }
  .oni-runner { width: 82px; }
  .dock-roll-button { flex-basis: 154px; grid-template-columns: 36px minmax(0, 1fr) 43px; min-height: 76px; }
  .dock-player-icon { width: 34px; height: 34px; font-size: 1.25rem; }
  .dock-die .die-shell { width: 40px; height: 40px; padding: 5px; }
  .dock-die .pip { width: 6px; height: 6px; }
}
.die-idle .die-shell { position: relative; }
.die-idle .pip { visibility: hidden; }
.die-idle .die-shell::after {
  content: "?";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #6d5746;
  font-size: 1.75rem;
  font-weight: 1000;
  text-shadow: 0 1px 0 #fff;
}
.dock-die.die-idle .die-shell::after { font-size: 1.2rem; }

/* ===== v0.1.7 mobile-first usability overhaul ===== */
.board {
  grid-template-columns: repeat(var(--board-columns, 10), minmax(64px, 1fr));
}

@media (max-width: 600px) {
  html, body { width: 100%; overflow-x: hidden; }
  body.game-running .app-shell { padding-bottom: 122px; }
  .app-shell { width: 100%; padding: 10px; }

  .hero-card {
    gap: 10px;
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 18px;
  }
  .hero-oni { width: 74px; }
  h1 { font-size: clamp(1.65rem, 9vw, 2.35rem); }
  .lead { margin-top: 8px; font-size: .9rem; line-height: 1.45; }
  .eyebrow { font-size: .72rem; }

  .setup-grid { gap: 12px; }
  .panel { padding: 14px; border-radius: 16px; }
  .field { margin-top: 12px; }
  select, textarea, input[type="text"] { min-height: 46px; font-size: 16px; }

  .player-inputs { gap: 12px; }
  .player-input-row {
    grid-template-columns: 34px minmax(0, 1fr) 46px;
    grid-template-rows: 46px 46px;
    gap: 7px 8px;
    padding: 10px;
    border: 1px solid #ead7c0;
    border-radius: 14px;
    background: #fffaf3;
  }
  .player-number { grid-column: 1; grid-row: 1 / span 2; align-self: center; }
  .player-name { grid-column: 2; grid-row: 1; min-width: 0; }
  .player-icon {
    grid-column: 2;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    font-size: 16px;
  }
  .player-color {
    grid-column: 3;
    grid-row: 1 / span 2;
    align-self: stretch;
    width: 46px;
    height: 100%;
  }

  .game-header {
    position: relative;
    gap: 8px;
    margin-bottom: 10px;
  }
  .game-header h1 { font-size: 1.8rem; }
  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }
  .header-actions .button,
  .header-actions .icon-button {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 7px 5px;
    font-size: .74rem;
    border-radius: 11px;
  }

  .status-strip {
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    margin-bottom: 9px;
  }
  .status-card {
    min-height: 68px;
    gap: 7px;
    padding: 9px 10px;
    border-radius: 13px;
  }
  .status-icon { font-size: 1.4rem; }
  .status-icon:has(.oni-illustration) { width: 40px; height: 38px; }
  .oni-mini { width: 42px; }
  .status-label { font-size: .67rem; }
  .status-card strong { font-size: .92rem; }
  .rule-status { grid-column: 1 / -1; min-height: 54px; }
  .rule-status strong { font-size: .84rem; line-height: 1.35; }
  .oni-status .button { padding: 6px; font-size: .68rem; }

  .game-layout { gap: 10px; }
  .board-panel { padding: 10px; }
  .board-toolbar { gap: 4px; margin-bottom: 8px; }
  .board-toolbar h2 { margin-bottom: 4px; font-size: 1.05rem; }
  .last-event { font-size: .82rem; line-height: 1.45; }
  .legend { display: none; }

  .board-viewport {
    width: 100%;
    min-height: 310px;
    max-height: 52vh;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 10px 7px 22px;
    scroll-padding: 70px;
    -webkit-overflow-scrolling: touch;
  }
  .board {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(var(--board-columns, 5), minmax(0, 1fr));
    grid-auto-rows: minmax(62px, auto);
    column-gap: 8px;
    row-gap: 20px;
    padding: 4px 3px 10px;
  }
  .cell {
    min-width: 0;
    min-height: 62px;
    padding: 5px;
    border-radius: 11px;
  }
  .cell-number { font-size: .64rem; padding: 1px 4px; }
  .cell-type { top: 4px; right: 4px; font-size: .72rem; }
  .tokens { gap: 1px; margin-top: 5px; }
  .player-token {
    width: 25px;
    height: 25px;
    font-size: .9rem;
    border-width: 1px;
  }
  .cell.route-right::after,
  .cell.route-left::after { width: 13px; }
  .cell.route-right::after { right: -12px; }
  .cell.route-left::after { left: -12px; }
  .route-right .route-arrow { right: -14px; }
  .route-left .route-arrow { left: -14px; }
  .route-arrow { width: 17px; height: 17px; font-size: .48rem; }

  .ghost-chaser {
    width: 66px;
    height: 56px;
    transform: translate(-49%, -62%);
  }
  .oni-runner { width: 66px; }
  .ghost-target {
    top: -5px;
    min-width: 39px;
    padding: 2px 5px;
    font-size: .58rem;
  }

  .side-panel { gap: 10px; }
  .mini-map-panel { padding: 12px; }
  .position-summary { gap: 9px; }
  .position-head { font-size: .82rem; }
  .log-panel { max-height: 220px; overflow: auto; }
  .event-log { font-size: .82rem; }

  .players-panel { padding: 12px; }
  .player-cards {
    display: flex;
    overflow-x: auto;
    gap: 9px;
    padding-bottom: 5px;
    scroll-snap-type: x mandatory;
  }
  .player-card {
    flex: 0 0 185px;
    padding: 12px;
    scroll-snap-align: start;
  }
  .player-name-label {
    max-width: 125px;
    font-size: .95rem;
  }
  .player-position { font-size: .76rem; }
  .player-card .dice-result { min-height: 62px; margin: 7px 0; }
  .player-card .die-shell { width: 48px; height: 48px; padding: 6px; }
  .player-card .pip { width: 7px; height: 7px; }
  .roll-hint { font-size: .7rem; }

  .dice-dock {
    min-height: 108px;
    grid-template-columns: 1fr;
    gap: 0;
    padding: 8px max(9px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left));
    border-radius: 18px 18px 0 0;
  }
  .dice-dock-title { display: none; }
  .dice-dock-buttons {
    display: flex;
    width: 100%;
    overflow-x: auto;
    gap: 8px;
    padding: 2px 2px 7px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .dock-roll-button {
    flex: 0 0 158px;
    min-height: 82px;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 8px;
    padding: 8px 10px;
    border-width: 2px;
    border-radius: 15px;
    scroll-snap-align: start;
  }
  .dock-player-icon {
    width: 38px;
    height: 38px;
    font-size: 1.35rem;
  }
  .dock-roll-text { align-self: center; }
  .dock-roll-text strong {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: .92rem;
    line-height: 1.13;
    overflow-wrap: anywhere;
  }
  .dock-roll-text small {
    margin-top: 3px;
    font-size: .69rem;
    line-height: 1.1;
  }
  .dock-die { display: none; }

  .modal-backdrop { align-items: end; padding: 10px; }
  .modal {
    width: 100%;
    max-height: 84dvh;
    padding: 20px 16px calc(18px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 14px 14px;
  }
  .modal-emoji { font-size: 3rem; }
  .modal h2 { font-size: 1.35rem; }
  .modal p { font-size: .95rem; }
  .modal-actions { display: grid; grid-template-columns: 1fr; }
  .modal-actions .button { width: 100%; min-height: 46px; }
}

@media (max-width: 360px) {
  .app-shell { padding: 7px; }
  .panel { padding: 11px; }
  .header-actions .button,
  .header-actions .icon-button { font-size: .67rem; }
  .status-card { padding: 8px; }
  .board { column-gap: 7px; }
  .dock-roll-button { flex-basis: 146px; }
}


/* v0.1.8: the selected ghost distance is a real head start, not part of the goal course. */
.field-help {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  line-height: 1.45;
}

.ghost-approach-lane {
  position: relative;
  min-height: 66px;
  border: 2px dashed #cb8a4d;
  border-radius: 18px;
  background: linear-gradient(90deg, rgba(230,244,255,.95), rgba(255,239,219,.96));
  overflow: visible;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.65), 0 4px 10px rgba(80,51,29,.08);
}

.ghost-approach-lane::before {
  content: "";
  position: absolute;
  left: 6%;
  right: 5%;
  top: 50%;
  height: 8px;
  border-radius: 999px;
  background: repeating-linear-gradient(90deg, #d7a05e 0 24px, #edc38e 24px 36px);
  transform: translateY(-50%);
}

.ghost-approach-lane::after {
  content: "";
  position: absolute;
  left: calc((100% / var(--board-columns, 10)) / 2);
  bottom: -28px;
  width: 9px;
  height: 29px;
  border-radius: 999px;
  background: #d7a05e;
  box-shadow: 0 0 0 3px rgba(255,255,255,.78);
  transform: translateX(-50%);
}

.approach-start-label,
.approach-ghost-label,
.approach-arrows {
  position: absolute;
  z-index: 3;
  font-weight: 900;
}

.approach-start-label {
  left: 10px;
  top: 6px;
  color: #286586;
  font-size: .72rem;
}

.approach-ghost-label {
  right: 10px;
  bottom: 6px;
  color: #93402e;
  font-size: .72rem;
}

.approach-arrows {
  left: 18%;
  right: 18%;
  top: 50%;
  color: #70441f;
  font-size: .78rem;
  letter-spacing: .12em;
  text-align: center;
  transform: translateY(-50%);
  opacity: .82;
}

@media (max-width: 600px) {
  .ghost-approach-lane { min-height: 58px; border-radius: 13px; }
  .ghost-approach-lane::after {
    left: calc((100% / var(--board-columns, 5)) / 2);
    bottom: -24px;
    height: 25px;
  }
  .approach-start-label,
  .approach-ghost-label { font-size: .6rem; }
  .approach-start-label { left: 6px; top: 4px; }
  .approach-ghost-label { right: 6px; bottom: 4px; }
  .approach-arrows { left: 22%; right: 12%; font-size: .63rem; letter-spacing: 0; }
}

/* v0.1.9: ghost speed choices 1-60 seconds, default 15 seconds. */


/* v0.1.9 final: MWY homepage branding */
.mwy-site-bar {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 14px 28px 0;
}
.mwy-site-link {
  width: fit-content;
  max-width: 100%;
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 13px 7px 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,.9);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 5px 18px rgba(94,57,26,.08);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.mwy-site-link:hover {
  transform: translateY(-1px);
  border-color: #ef9a62;
  box-shadow: 0 8px 22px rgba(94,57,26,.13);
}
.mwy-site-link:focus-visible {
  outline: 3px solid rgba(240,123,63,.35);
  outline-offset: 3px;
}
.mwy-site-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  object-fit: contain;
}
.mwy-site-copy {
  min-width: 0;
  display: grid;
  line-height: 1.12;
}
.mwy-site-copy strong {
  font-size: .98rem;
  letter-spacing: .015em;
}
.mwy-site-copy small {
  margin-top: 4px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}
.mwy-site-open {
  margin-left: 3px;
  color: var(--primary-dark);
  font-size: 1rem;
  font-weight: 900;
}

@media (max-width: 600px) {
  .mwy-site-bar { padding: 8px 8px 0; }
  .mwy-site-link {
    min-height: 44px;
    gap: 8px;
    padding: 5px 10px 5px 5px;
    border-radius: 13px;
  }
  .mwy-site-icon { width: 34px; height: 34px; flex-basis: 34px; }
  .mwy-site-copy strong { font-size: .87rem; }
  .mwy-site-copy small { margin-top: 2px; font-size: .64rem; }
  .mwy-site-open { font-size: .85rem; }
}
