:root {
  --ink: #3b2b22; --paper: #fffaf0; --accent: #e8775a; --leaf: #5f9c63; --sky: #bfe0d6;
  --kashiko: #f0a33c; --player: #5aa0d8; --danger: #e5484d;
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic", "Meiryo", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); color: var(--ink); }
#view, #overlay { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#overlay { pointer-events: none; }

.panel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  background: color-mix(in srgb, var(--paper) 94%, transparent); border-radius: 22px;
  box-shadow: 0 18px 50px #2b3a2a40, 0 0 0 3px #fff inset; padding: 26px 30px; z-index: 5;
}
.panel h1 { margin: 0 0 6px; font-size: clamp(30px, 5vw, 44px); letter-spacing: .04em; color: #7a4b2c; }
.panel h1 rt { font-size: 11px; color: #a07a5c; }
.panel h2 { margin: 0 0 10px; font-size: 20px; color: #7a4b2c; }
.lead { margin: 0 0 16px; line-height: 1.7; }
.how { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; font-size: 13.5px; line-height: 1.55; margin-bottom: 16px; }
.how div { background: #fff; border-radius: 12px; padding: 9px 12px; border: 1px solid #efe2cc; }
.how b { display: block; color: var(--accent); font-size: 14px; }
.how em { font-style: normal; background: #fff1b8; padding: 0 3px; border-radius: 3px; }
.brainbox { background: #f3f8ee; border: 1px solid #d6e6cc; border-radius: 16px; padding: 14px 16px; }
.keyrow { display: flex; gap: 10px; align-items: center; font-size: 13.5px; font-weight: 600; }
.keyrow input { flex: 1; min-width: 0; padding: 9px 11px; border-radius: 10px; border: 1px solid #c8d9bd; font: inherit; font-weight: 400; }
.consent { display: flex; gap: 8px; margin: 10px 0 12px; font-size: 12.5px; line-height: 1.55; color: #4e5e46; }
.consent input { margin-top: 3px; flex: none; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; }
button { font: inherit; font-weight: 700; border: 0; border-radius: 999px; padding: 11px 20px; cursor: pointer;
  background: #fff; color: var(--ink); box-shadow: 0 0 0 2px #e6d7bf inset; }
button.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 #b95a42; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:not(:disabled):hover { filter: brightness(1.05); }
.msg { font-size: 13px; min-height: 1.2em; margin: 10px 0 0; color: #6c5a48; }
.msg.err { color: var(--danger); }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.scoreboard { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px; align-items: flex-start; }
.side { background: #fffaf0e0; border-radius: 14px; padding: 7px 14px 9px; min-width: 190px; box-shadow: 0 4px 14px #0002; }
.side .name { font-weight: 800; margin-right: 10px; }
.side.kashiko .name { color: #c07718; } .side.player .name { color: #2f78b3; }
.pips { letter-spacing: 3px; font-size: 18px; }
.bar { height: 7px; background: #0001; border-radius: 9px; margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; border-radius: 9px; transition: width .1s linear; }
.kashiko .bar i { background: var(--kashiko); } .player .bar i { background: var(--player); }
.bar i.low { background: var(--danger); }
.round { white-space: nowrap; background: #7a4b2c; color: #fff; font-weight: 800; border-radius: 12px; padding: 10px 14px; margin-top: 4px; }
#bubble { position: absolute; transform: translate(-50%, -100%); background: #fff; border-radius: 16px; padding: 7px 13px; font-weight: 800;
  box-shadow: 0 4px 12px #0003; white-space: nowrap; font-size: 17px; }
#bubble::after { content: ""; position: absolute; left: 50%; bottom: -8px; border: 8px solid transparent; border-top-color: #fff; border-bottom: 0; transform: translateX(-50%); }
#banner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); font-size: clamp(48px, 9vw, 96px); font-weight: 900;
  color: #fff; -webkit-text-stroke: 3px #7a4b2c; text-shadow: 0 6px 0 #7a4b2c55; letter-spacing: .08em; animation: pop .35s ease-out; white-space: nowrap; }
#banner small { display: block; font-size: .3em; -webkit-text-stroke: 0; color: #7a4b2c; text-shadow: none; text-align: center; letter-spacing: 0; background: #fffaf0e8; border-radius: 10px; padding: 4px 10px; margin-top: 6px; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.4); opacity: 0; } }
#brainStatus { position: absolute; left: 50%; transform: translateX(-50%); top: 78px; white-space: nowrap; background: #fffaf0d8; border-radius: 10px; padding: 6px 11px; font-size: 12px; font-variant-numeric: tabular-nums; }
#controls { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: min(980px, calc(100vw - 20px));
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 14px; pointer-events: auto; }
#controls .group { display: flex; gap: 6px; }
#controls button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 12px; border-radius: 14px; min-width: 92px;
  background: #fffaf0e8; box-shadow: 0 3px 0 #0002, 0 0 0 2px #e6d7bf inset; touch-action: none; user-select: none; -webkit-user-select: none; }
#controls button b { font-size: 14px; }
#controls kbd { font: 600 11px/1.2 ui-monospace, Consolas, monospace; color: #7a6450; background: #0000000d; border-radius: 6px; padding: 2px 6px; }
#controls button.on { background: #dcecf8; box-shadow: 0 3px 0 #0002, 0 0 0 2px #5aa0d8 inset; }
#controls button.attack { background: #ffe3d8; box-shadow: 0 3px 0 #b95a4240, 0 0 0 2px #e8775a inset; }
#controls button.guard.on { background: #5aa0d8; color: #fff; } #controls button.guard.on kbd { color: #fff; }
#controls button.down { transform: translateY(2px); box-shadow: 0 1px 0 #0002, 0 0 0 2px #7a4b2c inset; }
#controls .small button { min-width: 0; } #controls .small b { font-size: 12px; }
#controls .movehint { width: 100%; text-align: center; margin: 0; font-size: 11.5px; color: #4e3b2e; }
#controls .movehint { width: auto; background: #fffaf0d8; border-radius: 8px; padding: 3px 10px; }
#pauseStats, #resultStats { font-size: 13.5px; line-height: 1.7; background: #fff; border-radius: 12px; padding: 10px 14px; margin: 10px 0 14px; border: 1px solid #efe2cc; }
#resultTitle { font-size: 34px; }
@media (max-width: 640px) { .how { grid-template-columns: 1fr; } .side { min-width: 120px; } #controls button { min-width: 0; padding: 6px 8px; } #controls kbd, #controls .movehint { display: none; } #brainStatus { display: none; } }

.sensrow { display: flex; gap: 8px; align-items: center; font-size: 13px; margin-top: 12px; }
.sensrow select { font: inherit; padding: 4px 8px; border-radius: 8px; border: 1px solid #c8d9bd; }
html[data-public-local="true"] .jev-only { display: none !important; }
html[data-public-jev="true"] .local-jev-only, html[data-public-jev="true"] .jev-only, html[data-public-jev="true"] .brainbox h2 { display: none !important; }
.public-local-note, .public-jev-note { display: none; }
html[data-public-local="true"] .public-local-note { display: block; }

/* ---------- Touch layout ---------- */
#touchControls, .touch-how { display: none; }
html.touch .desk-how, html.touch #controls, html.touch .sensrow { display: none !important; }
html.touch .touch-how { display: grid; }
html.touch #touchControls { display: block; position: absolute; inset: 0; pointer-events: none; }
html.touch, html.touch body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
html.touch #view { touch-action: none; }
#stick { position: absolute; left: calc(18px + env(safe-area-inset-left)); bottom: calc(22px + env(safe-area-inset-bottom));
  width: 128px; height: 128px; border-radius: 50%; background: #fffaf055; box-shadow: 0 0 0 3px #fffaf0aa inset; pointer-events: auto; touch-action: none; }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  background: #fffaf0e8; box-shadow: 0 3px 8px #0003; pointer-events: none; }
.tbtns { position: absolute; right: calc(16px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.tb { width: 78px; height: 78px; border-radius: 50%; padding: 0; font-size: 15px; line-height: 1.15; touch-action: none; box-shadow: 0 4px 0 #0002, 0 0 0 2px #e6d7bf inset; background: #fffaf0e8; }
.tb.parry { width: 92px; height: 92px; background: #5aa0d8; color: #fff; box-shadow: 0 4px 0 #2f78b3; font-size: 16px; }
.tb.down { transform: translateY(3px); }
.tpause { position: absolute; left: calc(12px + env(safe-area-inset-left)); top: calc(12px + env(safe-area-inset-top)); width: 44px; height: 44px; padding: 0; border-radius: 50%; pointer-events: auto; font-size: 16px; }
.thint { position: absolute; left: 50%; bottom: calc(160px + env(safe-area-inset-bottom)); transform: translateX(-50%); margin: 0; font-size: 12px; white-space: nowrap;
  background: #fffaf0c8; border-radius: 10px; padding: 4px 10px; animation: thintfade 1s 6s forwards; }
@keyframes thintfade { to { opacity: 0; } }
html.touch .scoreboard { top: calc(10px + env(safe-area-inset-top)); gap: 8px; }
html.touch .side { min-width: 0; padding: 5px 10px 7px; }
html.touch .round { padding: 7px 9px; font-size: 13px; }
@media (max-width: 480px) { html.touch .side .name { display: block; margin: 0; font-size: 13px; } html.touch .pips { font-size: 14px; } }

/* Music toggle */
#bgmToggle { position: absolute; right: calc(14px + env(safe-area-inset-right)); top: calc(14px + env(safe-area-inset-top)); width: 42px; height: 42px; padding: 0; border-radius: 50%;
  pointer-events: auto; font-size: 18px; background: #fffaf0e0; }
#bgmToggle.off { opacity: .5; text-decoration: line-through; }
/* Bonus bouts */
button.next { background: linear-gradient(135deg, #8a5cff, #e8775a); box-shadow: 0 4px 0 #5a38b8; animation: nextglow 1.4s ease-in-out infinite alternate; }
@keyframes nextglow { from { filter: brightness(1); } to { filter: brightness(1.18); } }
html[data-mode="serious"] #banner { color: #f3e6ff; -webkit-text-stroke-color: #4b2a8a; }
html[data-mode="revenge"] #banner { -webkit-text-stroke-color: #b3262b; }

/* Elements edition */
.edition { font-size: .45em; margin-left: .5em; padding: .1em .5em; border-radius: 8px; background: linear-gradient(90deg, #ff7a3a, #3aa0ff); color: #fff; vertical-align: middle; }
.elements { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; font-size: 14px; }
.elements .el { min-width: 84px; font-size: 18px; box-shadow: 0 0 0 2px #e6d7bf inset; }
.elements .el.fire.on { background: linear-gradient(135deg, #ffb35a, #e8492a); color: #fff; box-shadow: 0 4px 0 #a8321c; }
.elements .el.water.on { background: linear-gradient(135deg, #7fd6ff, #2a7fe8); color: #fff; box-shadow: 0 4px 0 #1c5aa8; }
#elementNote { color: #6c5a48; font-size: 13px; }
.how.techs { margin-bottom: 12px; }
#techName { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); font-weight: 900; font-size: clamp(22px, 4vw, 34px); letter-spacing: .12em;
  color: #fff; -webkit-text-stroke: 2px #7a4b2c; animation: techpop .9s ease-out forwards; pointer-events: none; white-space: nowrap; }
html[data-element="fire"] #techName { -webkit-text-stroke-color: #b3321c; text-shadow: 0 0 18px #ff8a2a; }
html[data-element="water"] #techName { -webkit-text-stroke-color: #1c5aa8; text-shadow: 0 0 18px #58c6ff; }
@keyframes techpop { 0% { opacity: 0; transform: translateX(-50%) scale(1.4); } 15% { opacity: 1; transform: translateX(-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translateX(-50%) translateY(-12px); } }

/* Ki gauge (special techniques) */
.bar.ki { height: 5px; margin-top: 3px; background: #0002; }
.bar.ki i { background: linear-gradient(90deg, #c9912a, #ffd76a); }
.bar.ki.full i { background: linear-gradient(90deg, #ffd76a, #fff6c8, #ffd76a); background-size: 200% 100%; animation: kiShine .8s linear infinite; box-shadow: 0 0 10px #ffd76a; }
@keyframes kiShine { to { background-position: -200% 0; } }
#kiHint { display: flex; gap: 6px; margin-top: 4px; font-size: 11px; justify-content: flex-end; flex-wrap: wrap; }
#kiHint span { padding: 1px 6px; border-radius: 9px; background: #0000000d; color: #8a7a68; transition: all .2s; white-space: nowrap; }
#kiHint span.ready { background: #ffd76a; color: #5a3a08; box-shadow: 0 0 8px #ffd76a; }
#kiHint b { font-weight: 800; }
.how .ougi span { display: block; margin-left: 1em; }
#techName.big { font-size: clamp(34px, 7vw, 64px); top: 40%; letter-spacing: .2em; }
html[data-element="fire"] #techName.big { text-shadow: 0 0 24px #ff8a2a, 0 0 60px #ff4a1a; }
html[data-element="water"] #techName.big { text-shadow: 0 0 24px #58c6ff, 0 0 60px #1f6fd6; }
#techName.dim { font-size: 18px; opacity: .8; -webkit-text-stroke-width: 1px; }
#kiHint span { pointer-events: auto; cursor: pointer; }
