/* ============================================================
   Shinobi Clash — style.css
   Bố cục: canvas toàn màn hình (edge-to-edge), HUD + nút cảm ứng
   phủ lên trên, các màn hình menu là lớp phủ tối. Một tông màu tối
   duy nhất (dark arcade), chữ hiển thị Oswald + thân Be Vietnam Pro.
   ============================================================ */
:root {
  --bg: #0b0a14;
  --surface: #161427;
  --surface2: #221f3a;
  --fg: #f3efe6;
  --muted: #a9a3bd;
  --accent: #ff3b4a;
  --green: #3ddc6a;
  --gold: #f5c242;
  --blue: #5ac8ff;
  --font-display: 'Oswald', 'Be Vietnam Pro', Impact, 'Arial Narrow', sans-serif;
  --font-body: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-body); overflow: hidden; overscroll-behavior: none; }
button { font-family: inherit; }
[hidden] { display: none !important; }

#app {
  position: fixed; inset: 0; overflow: hidden; background: var(--bg);
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  --canvas-h: 100%;
  --hud-h: 92px;
}
#game { position: absolute; left: 0; top: 0; display: block; background: #0b0a14; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; top: 0; width: 100%; height: var(--canvas-h); pointer-events: none; z-index: 3; }
.hud-top { position: absolute; top: calc(8px + var(--sa-t)); left: max(10px, var(--sa-l)); right: max(10px, var(--sa-r)); display: flex; align-items: flex-start; gap: 10px; }
.pbox { flex: 1; min-width: 0; }
.hpbar { height: 18px; background: rgba(0,0,0,0.6); border: 2px solid #f3efe6; border-radius: 3px; position: relative; overflow: hidden; transform: skewX(-14deg); box-shadow: 0 2px 6px rgba(0,0,0,0.5); }
.p2 .hpbar { transform: skewX(14deg); }
.hp, .hp-trail { position: absolute; inset: 0; transform-origin: left; }
.p2 .hp, .p2 .hp-trail { transform-origin: right; }
.hp { background: linear-gradient(#fff2b8, #f5c242 55%, #d98d1f); }
.hp.low { background: linear-gradient(#ffb0a6, #ff3b4a 55%, #a3141f); }
.hp-trail { background: #b3202c; }
.hud-row { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; gap: 8px; }
.p2 .hud-row { flex-direction: row-reverse; }
.pname { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: 1.5px; text-transform: uppercase; text-shadow: 0 2px 4px #000, 0 0 8px rgba(0,0,0,0.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wins { display: flex; gap: 4px; }
.wins i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #f3efe6; display: block; background: rgba(0,0,0,0.5); }
.wins i.on { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.mpbar { height: 8px; margin-top: 4px; width: 70%; background: rgba(0,0,0,0.6); border: 1.5px solid rgba(255,255,255,0.65); border-radius: 2px; overflow: hidden; position: relative; }
.p2 .mpbar { margin-left: auto; }
.mp { position: absolute; inset: 0; background: linear-gradient(90deg, #5ac8ff, #a06bff); transform-origin: left; }
.p2 .mp { transform-origin: right; background: linear-gradient(270deg, #5ac8ff, #a06bff); }
.mpbar.full .mp { background: linear-gradient(90deg, #ffe08a, #ff7a3a, #ff3b4a); animation: mpPulse 0.7s ease-in-out infinite alternate; }
.mpbar.full { border-color: #ffd37a; box-shadow: 0 0 8px rgba(255,180,80,0.7); }
.mpbar.flash { border-color: var(--accent); animation: shakeX 0.35s; }
.timer { font-family: var(--font-display); font-size: 42px; font-weight: 700; line-height: 1; min-width: 76px; text-align: center; color: var(--fg); text-shadow: 0 0 10px rgba(255,255,255,0.3), 0 3px 6px #000; font-variant-numeric: tabular-nums; }
.timer.urgent { color: var(--accent); animation: pulse 0.5s infinite alternate; }
.cds { display: flex; gap: 5px; margin-top: 6px; }
.p2 .cds { display: none; justify-content: flex-end; }
#hud.pvp .p2 .cds { display: flex; }
.cdot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.45); font: 700 12px var(--font-display); font-style: normal; display: flex; align-items: center; justify-content: center; color: #cfc9e0; background: conic-gradient(rgba(0,0,0,0.78) var(--cd, 0%), rgba(255,255,255,0.16) 0); }
.cdot.ready { border-color: var(--gold); color: #fff; background: rgba(245,194,66,0.4); box-shadow: 0 0 6px rgba(245,194,66,0.6); }
.cdot.ult.ready { border-color: var(--accent); background: rgba(255,59,74,0.45); box-shadow: 0 0 10px var(--accent); }
.hud-pause { position: absolute; top: calc(58px + var(--sa-t)); left: 50%; transform: translateX(-50%); pointer-events: auto; width: 44px; height: 34px; border-radius: 6px; border: 2px solid rgba(255,255,255,0.5); background: rgba(14,12,26,0.75); color: #fff; font-size: 14px; cursor: pointer; letter-spacing: 1px; }
.hud-pause:active { background: rgba(255,255,255,0.3); }

/* ---------- Nút cảm ứng ---------- */
#touch { position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: 2; --tbtn-alpha: 0.55; }
#app.is-portrait #touch { top: calc(var(--hud-h) + var(--sa-t) + var(--canvas-h)); }
#app.is-portrait #hud { height: calc(var(--hud-h) + var(--sa-t)); background: linear-gradient(#151330, #0b0a14); border-bottom: 1px solid rgba(255,255,255,0.08); }
#app.is-portrait .hud-top { top: calc(6px + var(--sa-t)); }
#app.is-portrait .hud-pause { top: calc(50px + var(--sa-t)); }
#app.is-portrait #game { top: calc(var(--hud-h) + var(--sa-t)); }
#app.is-portrait #announce { top: calc(var(--hud-h) + var(--sa-t)); }
.tbtn { position: absolute; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; color: #fff; opacity: var(--tbtn-alpha); border: 2px solid rgba(255,255,255,0.85); background: rgba(40,36,70,0.7); box-shadow: 0 2px 10px rgba(0,0,0,0.45), inset 0 0 0 2px rgba(0,0,0,0.25); touch-action: none; letter-spacing: 1px; text-shadow: 0 1px 2px #000; will-change: transform; }
.tbtn span { pointer-events: none; }
.tbtn.active { opacity: 1; transform: scale(0.93); background: rgba(255,255,255,0.4); }
.tbtn.dir { background: rgba(90,200,255,0.32); border-color: rgba(154,226,255,0.95); }
.tbtn.atk { background: rgba(255,59,74,0.45); border-color: #ff8a93; }
.tbtn.blk { background: rgba(90,200,255,0.4); border-color: #9be2ff; }
.tbtn.sk { background: rgba(245,194,66,0.32); border-color: #ffe08a; }
.tbtn.ult { background: rgba(160,80,255,0.5); border-color: #d9b3ff; box-shadow: 0 0 14px rgba(180,100,255,0.55); }
#touch.editing .tbtn { opacity: 0.95; outline: 2px dashed #fff; outline-offset: 3px; cursor: move; }

/* ---------- Thông báo ---------- */
#announce { position: absolute; left: 0; top: 0; width: 100%; height: var(--canvas-h); display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 4; }
.ann { font-family: var(--font-display); font-weight: 700; font-size: clamp(40px, 13vmin, 100px); letter-spacing: 5px; color: #fff; text-transform: uppercase; -webkit-text-stroke: 2px #1a0c14; text-shadow: 0 0 20px rgba(255,255,255,0.4), 0 5px 0 #1a0c14, 0 10px 24px rgba(0,0,0,0.7); opacity: 0; text-align: center; padding: 0 16px; }
.ann.show { animation: annIn 1.1s cubic-bezier(.2,.9,.3,1) forwards; }
.ann.fight { color: var(--gold); }
.ann.ko { color: var(--accent); }
.ann.win { color: var(--green); font-size: clamp(28px, 8vmin, 64px); }
#toast { position: absolute; left: 50%; bottom: calc(26px + var(--sa-b)); transform: translateX(-50%); background: rgba(14,12,26,0.94); border: 1px solid rgba(255,255,255,0.2); padding: 10px 16px; border-radius: 8px; z-index: 6; pointer-events: none; font-size: 14px; max-width: 90%; text-align: center; }
#toast.show { animation: toastIn 2.8s ease forwards; }
#rotate-hint { display: none; }

/* ---------- Màn hình ---------- */
#screens { position: absolute; inset: 0; z-index: 5; }
#screens.menu-bg { background: radial-gradient(ellipse at 50% 30%, rgba(45,22,66,0.78), rgba(8,6,18,0.93)); }
#screens.layout-mode { pointer-events: none; }
#screens.layout-mode .layout-bar { pointer-events: auto; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding-block: calc(12px + var(--sa-t)) calc(12px + var(--sa-b)); padding-left: max(16px, var(--sa-l)); padding-right: max(16px, var(--sa-r)); }
.screen.overlay { background: rgba(5,4,12,0.62); }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; max-height: 100%; width: 100%; max-width: 1100px; padding: 4px; }
h2 { font-family: var(--font-display); font-weight: 700; font-size: clamp(26px, 5vmin, 40px); letter-spacing: 3px; text-transform: uppercase; margin: 0 0 12px; text-align: center; text-shadow: 0 3px 8px rgba(0,0,0,0.6); text-wrap: balance; }
h2 small { display: block; font-size: 0.45em; color: var(--gold); letter-spacing: 4px; }
h3 { font-family: var(--font-display); letter-spacing: 2px; text-transform: uppercase; color: var(--gold); margin: 14px 0 6px; font-size: 18px; }
p { line-height: 1.5; }

/* Logo & menu */
.logo { text-align: center; margin-bottom: 20px; }
.logo-kanji { font-size: 64px; line-height: 1; color: var(--accent); text-shadow: 0 0 30px rgba(255,59,74,0.65); font-family: 'Hiragino Mincho ProN', 'Yu Mincho', 'Noto Serif CJK JP', serif; }
.logo h1 { font-family: var(--font-display); font-size: clamp(46px, 11vmin, 96px); line-height: 0.92; margin: 2px 0 8px; letter-spacing: 8px; color: #fff3d6; text-shadow: 0 0 24px rgba(255,200,120,0.45), 0 4px 0 #3a0c14, 0 10px 24px rgba(0,0,0,0.7); }
.logo h1 span { display: block; color: var(--accent); letter-spacing: 14px; font-size: 0.72em; text-shadow: 0 0 24px rgba(255,59,74,0.6), 0 4px 0 #3a0c14; }
.tagline { color: var(--muted); margin: 0; font-size: 14px; letter-spacing: 0.5px; }
.menu-btns { display: flex; flex-direction: column; gap: 12px; align-items: stretch; width: min(100%, 300px); }
.menu-foot { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; justify-content: center; }

.btn { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: 2px; text-transform: uppercase; color: var(--fg); background: linear-gradient(180deg, #2c2849, #1a1730); border: 2px solid rgba(255,255,255,0.28); border-left-width: 6px; border-left-color: var(--gold); border-radius: 6px; padding: 10px 24px; min-width: 240px; cursor: pointer; transition: transform .08s, background .15s, border-color .15s; box-shadow: 0 4px 0 #090812, 0 8px 18px rgba(0,0,0,0.5); }
.btn:hover, .btn:focus-visible { border-color: var(--gold); background: linear-gradient(180deg, #3c3663, #262142); outline: none; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #090812; }
.btn.primary { background: linear-gradient(180deg, #ff6372, #b31b2a); border-color: #ffb3b9; border-left-color: #fff; color: #fff; }
.btn.primary:hover, .btn.primary:focus-visible { background: linear-gradient(180deg, #ff7a88, #c92838); }
.btn.ghost { background: transparent; box-shadow: none; border-color: rgba(255,255,255,0.3); border-left-color: rgba(255,255,255,0.3); font-size: 16px; }
.btn.mini { min-width: 0; font-size: 14px; padding: 6px 14px; letter-spacing: 1px; border-left-width: 2px; border-left-color: rgba(255,255,255,0.28); }
.btn.big { font-size: 26px; padding: 14px 30px; }

/* Chọn chế độ */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; width: 100%; max-width: 980px; margin: 10px 0 18px; }
.card { background: rgba(22,20,39,0.9); border: 2px solid rgba(255,255,255,0.14); border-radius: 10px; padding: 16px; text-align: left; color: var(--fg); cursor: pointer; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card b { font-family: var(--font-display); font-size: 22px; letter-spacing: 1px; text-transform: uppercase; }
.card span { color: var(--muted); font-size: 13.5px; line-height: 1.4; }
.card:hover, .card:focus-visible { border-color: var(--gold); background: var(--surface2); outline: none; }

/* Chọn nhân vật */
.select-wrap { display: flex; flex-direction: column; align-items: center; }
.select-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: start; width: 100%; }
.sel-panel { background: rgba(22,20,39,0.88); border: 2px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 10px; min-width: 0; }
.sel-head { font-family: var(--font-display); font-size: 13px; letter-spacing: 3px; color: var(--muted); text-transform: uppercase; text-align: center; }
.portrait { width: 100%; max-width: 180px; height: auto; display: block; margin: 0 auto; }
.sel-name { font-family: var(--font-display); font-size: 24px; letter-spacing: 1px; text-align: center; text-transform: uppercase; text-shadow: 0 2px 6px rgba(0,0,0,0.6); }
.sel-title { text-align: center; color: var(--muted); font-size: 13px; }
.char-list { display: flex; gap: 8px; justify-content: center; margin: 8px 0; flex-wrap: wrap; }
.chip { font-family: var(--font-display); font-size: 15px; letter-spacing: 1px; padding: 6px 14px; border-radius: 20px; border: 2px solid var(--c); background: transparent; color: var(--fg); cursor: pointer; }
.chip.on { background: var(--c); color: #111; font-weight: 700; }
.sel-desc { font-size: 13px; color: var(--muted); margin: 6px 0; line-height: 1.4; }
.moves { list-style: none; padding: 0; margin: 0; font-size: 12.5px; line-height: 1.4; }
.moves li { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.moves .mv-head { color: var(--gold); font-family: var(--font-display); letter-spacing: 1.5px; text-transform: uppercase; border: 0; margin-top: 4px; font-size: 12px; }
.moves b { display: inline-block; min-width: 46px; color: #fff; font-family: var(--font-display); letter-spacing: 1px; }
.moves em { color: var(--muted); font-style: normal; }
.sel-mid { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 26px; }
.vs { font-family: var(--font-display); font-size: 48px; font-weight: 700; color: var(--accent); text-shadow: 0 0 18px rgba(255,59,74,0.55); line-height: 1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
select, input[type=range] { font: inherit; }
select { background: var(--surface2); color: var(--fg); border: 1px solid rgba(255,255,255,0.25); border-radius: 6px; padding: 7px 8px; min-width: 170px; }
input[type=range] { width: 170px; accent-color: var(--gold); }

/* Cài đặt / Hướng dẫn */
.settings-wrap, .help-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; width: 100%; max-width: 1000px; }
.settings-grid section, .help-wrap section { background: rgba(22,20,39,0.88); border: 2px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.help-wrap section { width: 100%; max-width: 1000px; gap: 4px; }
table.keys { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.keys td, table.keys th { padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,0.08); text-align: left; }
table.keys th { color: var(--gold); font-family: var(--font-display); letter-spacing: 1px; font-weight: 500; }
kbd, .keybtn { font-family: var(--font-display); font-size: 13px; letter-spacing: 1px; background: #2a2646; border: 1px solid rgba(255,255,255,0.3); border-bottom-width: 3px; border-radius: 5px; padding: 3px 9px; color: #fff; }
.keybtn { cursor: pointer; min-width: 64px; }
.keybtn.waiting { border-color: var(--gold); color: var(--gold); animation: pulse 0.5s infinite alternate; }
.tips { margin: 6px 0 0; padding-left: 18px; color: var(--muted); line-height: 1.6; }
.help-chars { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.help-char h4 { font-family: var(--font-display); font-size: 20px; letter-spacing: 1px; margin: 4px 0; text-transform: uppercase; }
.help-char h4 small { color: var(--muted); font-size: 12px; letter-spacing: 1px; margin-left: 6px; }
.help-char p { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }

/* Tạm dừng / kết quả */
.panel { background: rgba(14,12,26,0.94); border: 2px solid rgba(255,255,255,0.15); border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 10px; align-items: center; min-width: min(300px, 100%); max-height: 100%; overflow-y: auto; }
.panel h2 { margin-bottom: 8px; }
.result-title { font-size: clamp(36px, 10vmin, 76px); color: var(--green); letter-spacing: 6px; }
.lose .result-title { color: var(--accent); }
.result-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
.result-btns .btn { min-width: 0; }

/* Chỉnh bố cục nút */
.layout-bar { position: absolute; top: calc(8px + var(--sa-t)); left: 50%; transform: translateX(-50%); display: flex; gap: 12px; align-items: center; background: rgba(14,12,26,0.94); border: 1px solid rgba(255,255,255,0.2); padding: 8px 12px; border-radius: 10px; flex-wrap: wrap; justify-content: center; max-width: 96%; font-size: 13px; }
.layout-bar label { flex-direction: row; align-items: center; gap: 6px; }
.layout-bar input[type=range] { width: 110px; }

/* Animation */
@keyframes annIn { 0% { opacity: 0; transform: scale(2.3) rotate(-5deg); } 14% { opacity: 1; transform: scale(1) rotate(0); } 78% { opacity: 1; transform: scale(1.05); } 100% { opacity: 0; transform: scale(1.25); } }
@keyframes mpPulse { from { filter: brightness(1); } to { filter: brightness(1.5); } }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.55; } }
@keyframes shakeX { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes toastIn { 0% { opacity: 0; transform: translate(-50%, 10px); } 10% { opacity: 1; transform: translate(-50%, 0); } 85% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ann.show { animation-duration: 0.5s; } .mpbar.full .mp, .timer.urgent, .keybtn.waiting { animation: none; } }

/* Màn hình hẹp */
@media (max-width: 760px) {
  .select-grid { grid-template-columns: 1fr 1fr; }
  .sel-mid { grid-column: 1 / -1; order: 3; padding-top: 4px; }
  .moves { display: none; }
  .btn { min-width: 200px; font-size: 18px; }
}
@media (max-width: 560px), (max-height: 420px) {
  .timer { font-size: 30px; min-width: 56px; }
  .pname { font-size: 13px; letter-spacing: 1px; }
  .hpbar { height: 14px; }
  .cdot { width: 20px; height: 20px; font-size: 10px; }
  .hud-pause { top: calc(44px + var(--sa-t)); width: 38px; height: 28px; font-size: 11px; }
  .logo-kanji { font-size: 44px; }
  .logo { margin-bottom: 10px; }
  .menu-btns { gap: 8px; }
  .btn { padding: 8px 18px; }
  .btn.big { font-size: 22px; padding: 10px 24px; }
  h2 { margin-bottom: 8px; }
  .cards { gap: 8px; }
  .card { padding: 10px 12px; }
}
@media (max-height: 420px) {
  .screen { justify-content: flex-start; }
  #scr-menu { justify-content: center; }
  .panel { padding: 12px 18px; gap: 6px; }
}

/* Bảng tạm dừng / kết quả cuộn được trên màn hình thấp nhưng không giãn hết chiều rộng */
.panel.scroll { width: auto; max-width: min(520px, 100%); padding: 24px; }
@media (max-height: 420px) { .panel.scroll { padding: 12px 18px; } }
