[hidden] { display: none !important; }
:root { --cell: min(11vw, 76px); --light: #eadbc0; --dark: #d6c19c; --bg: #f5efe4; --ink: #2b2118; }
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
select, button { font: inherit; font-size: 14px; padding: 4px 8px; border-radius: 6px; border: 1px solid #8a7a66; background: #fffaf2; color: var(--ink); cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
main { display: flex; flex-wrap: wrap; gap: 24px; padding: 16px; justify-content: center; }
#shrinkWarn { background: #b3261e; color: white; padding: 6px 10px; border-radius: 6px; margin-bottom: 8px; font-weight: 600; }
#boardWrap { display: inline-block; padding: 0 0 22px 22px; position: relative; }
#board { display: grid; grid-template-columns: repeat(7, var(--cell)); grid-template-rows: repeat(7, var(--cell)); border: 3px solid #5a4632; user-select: none; }
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.l { background: var(--light); } .sq.d { background: var(--dark); }
.sq.font { background: #8fd0f0; box-shadow: inset 0 0 0 3px #2a78b8; }
.sq.wall { background: repeating-linear-gradient(45deg, #4a3d33, #4a3d33 6px, #3a2f27 6px, #3a2f27 12px); }
.sq.doom::after { content: ""; position: absolute; inset: 2px; border: 2px dashed #d0342c; pointer-events: none; }
.sq .coord { position: absolute; font-size: 11px; color: #5a4632; }
.sq .rank { left: -18px; top: 40%; } .sq .file { bottom: -19px; left: 45%; }
.sq.sel { box-shadow: inset 0 0 0 4px #f0b400; }
.sq.lastfrom { box-shadow: inset 0 0 0 3px rgba(240,180,0,.45); } .sq.lastto { box-shadow: inset 0 0 0 3px rgba(240,180,0,.9); }
.sq.target { cursor: pointer; }
.mark { position: absolute; border-radius: 50%; pointer-events: none; z-index: 3; }
.mark.move { width: 28%; height: 28%; background: rgba(40,150,60,.75); }
.mark.revive { width: 34%; height: 34%; background: rgba(140,60,190,.8); }
.mark.shove { inset: 4px; border: 5px solid rgba(230,130,0,.9); border-radius: 12px; }
.mark.shoot { inset: 4px; border: 5px solid rgba(210,30,30,.9); }
.piece { width: 82%; height: 82%; position: relative; z-index: 2; cursor: pointer; }
.piece svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.badge { position: absolute; font-size: calc(var(--cell) * .24); line-height: 1; z-index: 4; }
.badge.frz { top: -4px; left: -4px; } .badge.prot { top: -4px; right: -4px; } .badge.ward { bottom: -4px; right: -2px; color: #2e9a4a; text-shadow: 0 0 2px #fff; }
.piece.frozen svg { filter: drop-shadow(0 0 5px #3aa0ff) saturate(.5); }
.piece.actable { animation: none; }
#legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; margin-top: 4px; max-width: calc(var(--cell) * 7 + 22px); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot.move { background: rgba(40,150,60,.8);} .dot.shove { background: rgba(230,130,0,.9);} .dot.shoot { background: rgba(210,30,30,.9);} .dot.revive { background: rgba(140,60,190,.8);}
#choice { margin-top: 8px; display: flex; gap: 8px; align-items: center; background: #fffaf2; border: 2px solid #f0b400; border-radius: 8px; padding: 8px; }
aside { width: 340px; max-width: 100%; }
#sides { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sidebox { background: #fffaf2; border: 1px solid #cdbb9f; border-radius: 8px; padding: 8px; font-size: 13px; }
.sidebox.tomove { border: 2px solid #f0b400; }
.sidebox h4 { margin: 0 0 4px; }
#actions { margin: 10px 0; display: flex; flex-wrap: wrap; gap: 6px; }
#log { max-height: 240px; overflow-y: auto; background: #fffaf2; border: 1px solid #cdbb9f; border-radius: 8px; padding: 6px 6px 6px 34px; font-size: 13px; margin: 0; }
#log li { padding: 1px 0; }
h3 { margin: 12px 0 6px; font-size: 15px; }
#rules { margin-top: 12px; font-size: 13px; background: #fffaf2; border: 1px solid #cdbb9f; border-radius: 8px; padding: 6px 10px; }
#rules summary { font-weight: 700; cursor: pointer; }
#rules li { margin-bottom: 4px; }
#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 20; }
#overlay[hidden] { display: none; }
#winBox { background: #fffaf2; padding: 24px 32px; border-radius: 12px; text-align: center; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
#winBox h2 { margin-top: 0; }
.thinking::after { content: " …thinking"; font-weight: 400; color: #8a7a66; }


#apCounter .hint { color: #6b5a48; font-size: 12px; }
.pip { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: #f0b400; border: 2px solid #8a6a00; }
.pip.used { background: #cdbb9f; border-color: #9a8a76; }
.piece.acted { opacity: .45; } .piece.acted svg { filter: grayscale(1); }
.piece.stunned svg { filter: drop-shadow(0 0 5px #b05cff) saturate(.6); }
.badge.stun { top: -4px; left: -4px; } .badge.done { bottom: -4px; left: -2px; color: #555; font-weight: 700; }
button.primary { background: #f0b400; border-color: #8a6a00; font-weight: 700; }

/* ---------- touch / phone ---------- */
:root { --cell: max(44px, min(76px, calc((100vw - 48px) / 7))); }
html { -webkit-text-size-adjust: 100%; }
#board, #board * , button, select, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
select, button { min-height: 44px; min-width: 44px; padding: 6px 12px; }
#rules summary { min-height: 44px; display: flex; align-items: center; }
#thinking { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 6px; padding: 4px 12px; border-radius: 999px; background: #2b2118; color: #f5efe4; font-size: 14px; font-weight: 600; }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #f0b400; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }
#boardCol { max-width: 100%; min-width: 0; }

/* ---------- tutorial ---------- */
#tutPanel { background: #fffaf2; border: 2px solid #f0b400; border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; max-width: calc(var(--cell) * 7 + 22px); }
.tutHead { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
#tutText { margin: 6px 0; font-size: 15px; line-height: 1.35; min-height: 3.9em; }
#tutActs { display: flex; flex-wrap: wrap; gap: 6px; }
#tutActs:empty { display: none; }
#tutActs span { display: none; }
.tutNav { display: flex; gap: 8px; margin-top: 6px; }
.tutNav button { flex: 1; }
.sq.tuthl::before { content: ""; position: absolute; inset: 1px; border: 3px solid #f0b400; border-radius: 4px; box-shadow: 0 0 8px 2px rgba(240,180,0,.8); pointer-events: none; z-index: 1; animation: tutpulse 1.2s ease-in-out infinite; }
@keyframes tutpulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .sq.tuthl::before { animation: none; } }
body.tutorial #howTo, body.tutorial #menuBtn, body.tutorial #ctrlRow, body.tutorial #playbar { display: none !important; }
body.tutorial #status, body.tutorial #shrinkWarn, body.tutorial #legend { display: none; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.modalBox { background: #fffaf2; border-radius: 12px; padding: 20px 22px; max-width: 400px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.modalBox h2 { margin: 0 0 8px; }
.modalBtns { display: flex; gap: 10px; margin: 14px 0 8px; }
.modalBtns button { flex: 1; }
.modalBox .small { font-size: 13px; color: #6b5a48; margin: 0; }
button.howto { font-weight: 600; }
@media (max-width: 700px) { #tutPanel { max-width: 100%; } }
/* phone landscape: tutorial panel sits to the right of the board */
@media (orientation: landscape) and (max-height: 500px) {
  body.tutorial header { display: none; }
  body.tutorial aside { display: none; }
  body.tutorial #tutPanel { position: fixed; top: 6px; right: 8px; bottom: 6px; left: calc(var(--cell) * 7 + 50px); max-width: none; overflow-y: auto; margin: 0; display: flex; flex-direction: column; }
  body.tutorial #tutText { flex: 1; }
  #legend { gap: 4px 10px; }
}
body.tutorial:not(.tutap) #apCounter { display: none !important; }

/* AI action animation + last-turn highlight */
.sq.lastturn::after { content: ''; position: absolute; inset: 0; background: rgba(240,180,0,.22); pointer-events: none; }
.shotline { position: absolute; height: 4px; transform-origin: 0 50%; background: linear-gradient(90deg, #ffd04a, #ff3b1f); box-shadow: 0 0 8px #ff6a00; border-radius: 2px; pointer-events: none; z-index: 6; }
.piece.ghost { display: flex; align-items: center; justify-content: center; }

@media (prefers-reduced-motion: reduce) { .shotline { display: none; } }
.piece.ghost svg { width: 82%; height: 82%; }

/* ---------- layout (2026-10-13 UX redesign): top bar · board · one control row; setup in a sheet ---------- */
:root { --cell: max(44px, min(76px, calc((100vw - 40px) / 7), calc((100vh - 230px) / 7))); --colw: calc(var(--cell) * 7 + 28px); }
header#topbar { display: flex; align-items: center; gap: 8px; padding: 4px 10px; padding-top: max(4px, env(safe-area-inset-top)); background: #2b2118; color: #f5efe4; min-height: 52px; }
header#topbar h1 { margin: 0; font-size: 20px; letter-spacing: 4px; }
header#topbar .grow { flex: 1; }
header#topbar button { background: #3e3127; color: #f5efe4; border-color: #6b5a48; font-weight: 600; }
main { display: flex; flex-wrap: wrap; gap: 24px; padding: 12px 16px; justify-content: center; align-items: flex-start; }
#boardCol { width: var(--colw); max-width: 100%; min-width: 0; }
#statusRow { display: flex; align-items: center; gap: 8px; min-height: 32px; margin-bottom: 4px; flex-wrap: wrap; }
#status { font-size: 16px; font-weight: 600; flex: 1 1 auto; min-width: 0; }
#thinking { margin: 0; padding: 3px 10px; font-size: 13px; }
#apCounter { display: flex; align-items: center; gap: 5px; font-size: 13px; background: #fffaf2; border: 1px solid #cdbb9f; border-radius: 8px; padding: 3px 8px; margin-left: auto; }
#apCounter .hint { display: none; }
#shrinkWarn { padding: 4px 8px; margin-bottom: 4px; font-size: 13px; }
#boardWrap { padding: 0 0 18px 18px; }
.sq .rank { left: -15px; } .sq .file { bottom: -17px; }
#lastAct { font-size: 14px; color: #5a4632; min-height: 1.3em; line-height: 1.3; margin: 2px 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lastAct:empty::before { content: "\00a0"; }
#ctrlRow, #playbar { display: flex; align-items: center; gap: 6px; }
#ctrlRow #actions { flex: 1; display: flex; gap: 6px; margin: 0; flex-wrap: nowrap; min-width: 0; justify-content: center; }
#ctrlRow #actions button { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 6px 8px; }
#undo { flex: 0 0 auto; }
#endTurn { flex: 0 0 auto; min-width: 120px; }
#playbar { flex-wrap: wrap; margin-top: 6px; background: #fffaf2; border: 1px solid #cdbb9f; border-radius: 10px; padding: 4px; }
#playbar button { flex: 1 1 44px; padding: 6px 4px; font-size: 16px; }
#playbar #pause { font-weight: 700; background: #f0b400; border-color: #8a6a00; }
#pbCount { font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600; padding: 0 6px; white-space: nowrap; }
#playbar .speed { margin-left: auto; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#legend { margin-top: 8px; max-width: 100%; }
aside { width: 340px; max-width: 100%; }
/* settings sheet: bottom sheet on phones, right drawer on wide screens */
#sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; display: flex; align-items: flex-end; justify-content: center; }
#sheetBox { background: #fffaf2; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; border-radius: 14px 14px 0 0; padding: 10px 16px max(16px, env(safe-area-inset-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,.35); animation: sheetUp .2s ease-out; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #sheetBox { animation: none; } }
.sheetHead { display: flex; align-items: center; justify-content: space-between; }
.sheetHead h2 { margin: 0; font-size: 18px; }
#controls { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 8px 0; }
#controls label { display: grid; grid-template-columns: 7.5em 1fr; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
#controls select { width: 100%; min-width: 0; }
#sheetBox .small { font-size: 12px; color: #6b5a48; margin: 4px 0 10px; }
button.wide { width: 100%; }
@media (min-width: 900px) {
  #sheet { justify-content: flex-end; align-items: stretch; }
  #sheetBox { max-width: 380px; max-height: none; border-radius: 0; padding: 16px 20px; animation-name: sheetIn; }
  @keyframes sheetIn { from { transform: translateX(40px); opacity: 0; } }
}
/* phones (portrait) */
@media (max-width: 700px) {
  header#topbar .lbl { display: none; }
  header#topbar h1 { font-size: 18px; }
  main { padding: 6px 8px; gap: 14px; }
  #boardCol { margin: 0 auto; }
  #boardWrap { padding: 0 0 17px 15px; }
  .sq .rank { left: -13px; }
  aside { width: 100%; }
}
@media (max-width: 380px) { #status { font-size: 14px; } #endTurn { min-width: 100px; } }
/* phone landscape: board on the left (sized by height), status + controls in a column to its right */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --cell: max(44px, min(76px, calc((100vh - 84px) / 7))); }
  header#topbar { min-height: 48px; padding-top: 2px; padding-bottom: 2px; }
  header#topbar .lbl { display: none; }
  main { padding: 4px 8px; justify-content: flex-start; gap: 12px; }
  #boardCol { width: auto; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 14px; align-content: start; align-items: start; }
  #boardCol > * { grid-column: 2; }
  #boardWrap { grid-column: 1; grid-row: 1 / span 9; }
  #tutPanel { grid-column: 1 / -1; }
  #lastAct { white-space: normal; }
  #ctrlRow { flex-wrap: wrap; }
  #legend { gap: 4px 10px; }
  aside { width: 100%; }
}
