:root {
  --navy-900: #060f1f;
  --navy-800: #0b1b33;
  --navy-700: #12294a;
  --navy-600: #1b3a66;
  --gold-100: #fff2c6;
  --gold-300: #ffd35e;
  --gold-500: #e8b53a;
  --gold-700: #a8741a;
  --gold-900: #6b4709;
  --cream: #fff6e0;
  --burgundy: #a3243b;
  --emerald: #1f7a5a;
  --ink: #0a1424;
  --font-display: 'Baloo 2', 'Be Vietnam Pro', system-ui, sans-serif;
  --font-body: 'Be Vietnam Pro', system-ui, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--cream);
  background: var(--navy-900);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: rgba(255, 246, 224, .65); font-size: 14px; line-height: 1.5; }

/* ---------- Nền vest kẻ sọc ---------- */
#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0; display: none; flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(60, 110, 190, .35), transparent 62%),
    repeating-linear-gradient(90deg, rgba(232, 181, 58, .09) 0 1px, transparent 1px 22px),
    linear-gradient(180deg, var(--navy-700), var(--navy-900));
  overflow-y: auto;
}
.screen.active { display: flex; }
#screen-game { overflow: hidden; background: #000; }

/* ---------- Logo / wordmark ---------- */
.brandbar { display: flex; align-items: center; gap: 12px; padding: 14px 24px; flex: none; }
.brandbar__logo { width: 46px; height: 46px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); }
.wordmark { display: flex; flex-direction: column; line-height: 1; }
.wordmark b { font-family: var(--font-serif); font-weight: 800; letter-spacing: .22em; font-size: 20px; color: var(--gold-300); }
.wordmark span { font-family: var(--font-serif); font-weight: 600; letter-spacing: .5em; font-size: 11px; color: var(--cream); margin-top: 3px; }
.wordmark i { font-style: normal; font-size: 9px; letter-spacing: .3em; color: rgba(255,246,224,.55); margin-top: 6px; }
.wordmark--sm b { font-size: 14px; }
.wordmark--sm span { font-size: 8px; }

/* ---------- Nút kiểu game: chunky, bóng, đổ đáy ---------- */
.btn {
  position: relative; font-family: var(--font-display); font-weight: 800; letter-spacing: .03em;
  font-size: 17px; line-height: 1; padding: 14px 24px; border-radius: 16px; cursor: pointer;
  border: 3px solid var(--ink); color: var(--ink); text-transform: uppercase;
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
  user-select: none; touch-action: manipulation; overflow: hidden;
}
.btn::before { /* vệt bóng */
  content: ''; position: absolute; left: 6%; right: 6%; top: 3px; height: 42%;
  border-radius: 12px 12px 40px 40px / 12px 12px 18px 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.65), rgba(255,255,255,.05)); pointer-events: none;
}
.btn small { font-weight: 500; font-size: 11px; opacity: .8; text-transform: none; letter-spacing: 0; }
.btn--gold {
  background: linear-gradient(180deg, var(--gold-300), var(--gold-500) 55%, #d49a22);
  box-shadow: 0 6px 0 var(--gold-900), 0 10px 18px rgba(0,0,0,.45);
}
.btn--navy {
  color: var(--cream); background: linear-gradient(180deg, #2c5a9a, var(--navy-600) 55%, #153059);
  border-color: #040a14; box-shadow: 0 5px 0 #040a14, 0 9px 16px rgba(0,0,0,.4);
}
.btn--navy::before { background: linear-gradient(180deg, rgba(255,255,255,.28), rgba(255,255,255,0)); }
.btn--xl { font-size: 26px; padding: 18px 40px; border-radius: 22px; }
.btn--sm { font-size: 13px; padding: 9px 14px; border-radius: 12px; border-width: 2px; box-shadow-offset: 0; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); }
.btn--gold:active { box-shadow: 0 2px 0 var(--gold-900), 0 4px 8px rgba(0,0,0,.4); }
.btn--navy:active { box-shadow: 0 1px 0 #040a14, 0 3px 8px rgba(0,0,0,.4); }
.btn:disabled { filter: grayscale(.7) brightness(.8); cursor: not-allowed; }
.btn:focus-visible, .iconbtn:focus-visible, input:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.iconbtn {
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-family: var(--font-display); font-weight: 800; font-size: 20px;
  color: var(--ink); border: 3px solid var(--ink);
  background: linear-gradient(180deg, var(--gold-300), var(--gold-500));
  box-shadow: 0 4px 0 var(--gold-900), 0 6px 12px rgba(0,0,0,.4);
  display: grid; place-items: center; touch-action: manipulation; user-select: none;
}
.iconbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-900); }
.iconbtn--sm { width: 34px; height: 34px; font-size: 14px; border-width: 2px; }
.iconbtn.off { filter: grayscale(1); opacity: .6; }

/* ---------- Ruy băng tiêu đề ---------- */
.ribbon { display: inline-block; position: relative; margin-bottom: 12px; }
.ribbon span {
  display: inline-block; padding: 6px 28px; font-family: var(--font-display); font-weight: 800; letter-spacing: .08em; font-size: 15px;
  color: var(--cream); background: linear-gradient(180deg, #c8344d, var(--burgundy)); border: 2px solid var(--ink);
  border-radius: 6px; box-shadow: 0 3px 0 #5f1020; position: relative;
}
.ribbon span::before, .ribbon span::after {
  content: ''; position: absolute; top: 6px; width: 16px; height: 100%; background: #7d1a2c; border: 2px solid var(--ink); z-index: -1;
}
.ribbon span::before { left: -14px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 35% 50%); }
.ribbon span::after { right: -14px; clip-path: polygon(0 0, 100% 0, 65% 50%, 100% 100%, 0 100%); }
.ribbon--center { display: block; text-align: center; margin: 0 auto 16px; }

/* ---------- Trang chủ ---------- */
.home { flex: 1; display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 24px; padding: 0 5vw 24px; max-width: 1200px; width: 100%; margin: 0 auto; }
.home__board { display: grid; place-items: center; }
.home__board canvas { width: min(46vw, 520px); height: auto; max-height: 70vh; aspect-ratio: 1; animation: floaty 5s ease-in-out infinite; filter: drop-shadow(0 20px 30px rgba(0,0,0,.6)); }
@keyframes floaty { 50% { transform: translateY(-10px) rotate(1.5deg); } }
.title {
  font-family: var(--font-display); font-weight: 800; font-size: clamp(54px, 9vw, 104px); line-height: .9; letter-spacing: .02em;
  color: var(--gold-300); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--gold-900), 0 14px 24px rgba(0,0,0,.5);
  margin-bottom: 14px;
}
.sub { max-width: 460px; line-height: 1.55; color: rgba(255,246,224,.85); margin-bottom: 22px; }
.menu { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.menu__row { display: flex; gap: 12px; flex-wrap: wrap; }
.period { margin-top: 18px; font-size: 13px; color: rgba(255,246,224,.55); }

/* ---------- Card / form ---------- */
.center { flex: 1; display: grid; place-items: center; padding: 8px 16px 28px; }
.card {
  width: min(520px, 100%); padding: 26px 26px 24px; border-radius: 24px;
  background: linear-gradient(180deg, rgba(18, 41, 74, .96), rgba(8, 20, 40, .98));
  border: 3px solid var(--gold-500); box-shadow: 0 0 0 3px var(--ink), 0 24px 50px rgba(0,0,0,.6), inset 0 0 40px rgba(232,181,58,.08);
}
.card--sm { width: min(440px, 92%); text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; flex: 1; min-width: 0; }
.field-row { display: flex; gap: 12px; }
.field label { font-family: var(--font-display); font-weight: 700; font-size: 14px; letter-spacing: .04em; color: var(--gold-300); }
input, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--cream); border: 3px solid var(--ink); border-radius: 12px;
  padding: 11px 14px; width: 100%; box-shadow: inset 0 3px 0 rgba(0,0,0,.12);
}
input::placeholder { color: #8a8470; }
input.invalid { border-color: var(--burgundy); background: #ffe9e9; }
.turnsbox {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; margin-bottom: 8px; border-radius: 14px;
  background: rgba(232,181,58,.12); border: 2px dashed var(--gold-500);
}
.turnsbox__label { font-weight: 600; }
.turnsbox__num { font-family: var(--font-display); font-weight: 800; font-size: 34px; color: var(--gold-300); line-height: 1; }
.form-error { min-height: 22px; color: #ff8c9b; font-weight: 600; font-size: 14px; margin: 6px 0; }
.form-actions { display: flex; gap: 12px; justify-content: space-between; }
.form-actions .btn--gold { flex: 1; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(2, 8, 18, .78); backdrop-filter: blur(4px); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal__box {
  position: relative; z-index: 2; width: min(620px, 100%); max-height: 88vh; overflow-y: auto; padding: 26px; border-radius: 24px;
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800)); border: 3px solid var(--gold-500);
  box-shadow: 0 0 0 3px var(--ink), 0 30px 60px rgba(0,0,0,.7); display: flex; flex-direction: column; gap: 14px; align-items: center;
  animation: pop .25s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.list { align-self: stretch; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; line-height: 1.55; font-size: 15px; }
.list li::marker { color: var(--gold-300); font-weight: 700; }
.list--num { list-style: decimal; }
.prizes { align-self: stretch; display: flex; flex-direction: column; gap: 10px; }
.prize {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 14px; background: rgba(0,0,0,.28); border: 2px solid rgba(232,181,58,.45);
}
.prize__pts { flex: none; min-width: 74px; text-align: center; font-family: var(--font-display); font-weight: 800; font-size: 24px; line-height: 1; color: var(--ink);
  background: linear-gradient(180deg, var(--gold-300), var(--gold-500)); border: 2px solid var(--ink); border-radius: 12px; padding: 8px 6px; }
.prize__pts small { display: block; font-size: 10px; letter-spacing: .1em; font-weight: 700; margin-top: 2px; }
.prize__name { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--gold-100); }
.prize__desc { font-size: 13px; color: rgba(255,246,224,.65); }
.prize__left { margin-left: auto; font-size: 12px; color: #ffb4bf; white-space: nowrap; }

/* ---------- Kết quả ---------- */
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.result { text-align: center; }
.result__name { font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.result__score { display: flex; flex-direction: column; align-items: center; }
.result__score span { font-size: 12px; letter-spacing: .2em; color: rgba(255,246,224,.6); }
.result__score b { font-family: var(--font-display); font-weight: 800; font-size: 76px; line-height: 1; color: var(--gold-300); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--gold-900); }
.result__prize { align-self: stretch; padding: 16px; border-radius: 16px; background: linear-gradient(180deg, rgba(232,181,58,.22), rgba(232,181,58,.06)); border: 2px dashed var(--gold-500); }
.result__prize small { display: block; font-size: 12px; letter-spacing: .15em; color: var(--gold-300); margin-bottom: 4px; }
.result__prize b { font-family: var(--font-display); font-size: 26px; font-weight: 800; color: var(--gold-100); line-height: 1.15; display: block; }
.result__throws { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); }
.chip b { color: var(--gold-300); }

/* ---------- Game stage ---------- */
.stage { position: relative; flex: 1; width: 100%; height: 100%; background: #000; user-select: none; -webkit-user-select: none; touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.hud { position: absolute; left: 0; right: 0; pointer-events: none; display: flex; padding: 10px 14px; gap: 12px; }
.hud > * { pointer-events: auto; }
.hud--top { top: 0; align-items: flex-start; justify-content: space-between; }
.hud--top .scoreboard { margin-right: auto; }
.hud--bottom { bottom: 0; align-items: flex-end; justify-content: space-between; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.hud__brand { display: flex; align-items: center; gap: 8px; }
.hud__brand img { width: 36px; height: 36px; }
.hud__tools { display: flex; gap: 8px; }
.scoreboard {
  display: flex; gap: 2px; padding: 6px; border-radius: 16px; background: rgba(6, 15, 31, .82); border: 3px solid var(--gold-500); box-shadow: 0 0 0 2px var(--ink), 0 8px 18px rgba(0,0,0,.5);
}
.scoreboard__item { padding: 2px 14px; text-align: center; min-width: 90px; }
.scoreboard__item + .scoreboard__item { border-left: 1px solid rgba(232,181,58,.35); }
.scoreboard__item span { display: block; font-size: 10px; letter-spacing: .14em; color: rgba(255,246,224,.6); }
.scoreboard__item b { font-family: var(--font-display); font-weight: 800; font-size: 20px; line-height: 1.1; color: var(--cream); display: block; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard__item--score b { color: var(--gold-300); font-size: 26px; }
.scoreboard.bump .scoreboard__item--score b { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.4); color: #fff; } }

.darts { position: absolute; top: 74px; left: 14px; display: flex; flex-direction: column; gap: 4px; max-height: 50vh; flex-wrap: wrap; pointer-events: none; }
.darts i { width: 34px; height: 8px; border-radius: 4px 1px 1px 4px; background: linear-gradient(90deg, var(--gold-300), #c9ced6 40%, #6e7684); border: 1px solid var(--ink); position: relative; }
.darts i::after { content: ''; position: absolute; right: -9px; top: -3px; width: 10px; height: 12px; background: var(--burgundy); clip-path: polygon(0 40%, 100% 0, 100% 100%, 0 60%); }
.darts i.used { opacity: .18; }

.phase-banner {
  position: absolute; top: 64px; right: 14px; padding: 8px 22px; border-radius: 14px; font-family: var(--font-display); font-weight: 800; letter-spacing: .06em; font-size: 16px;
  color: var(--ink); background: linear-gradient(180deg, var(--gold-300), var(--gold-500)); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--gold-900); pointer-events: none; text-align: center;
}
.phase-banner small { display: block; font-weight: 600; font-size: 12px; letter-spacing: 0; }

.hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); padding: 8px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; white-space: nowrap;
  background: rgba(6, 15, 31, .85); border: 2px solid var(--gold-500); pointer-events: none; transition: opacity .2s; max-width: 94vw; overflow: hidden; text-overflow: ellipsis;
}
.hint kbd { font-family: var(--font-display); font-weight: 800; font-size: 12px; padding: 1px 8px; border-radius: 6px; color: var(--ink); background: var(--gold-300); }

.stance { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 16px; background: rgba(6,15,31,.82); border: 2px solid rgba(232,181,58,.6); width: 190px; }
.stance__title, .power__title { font-size: 10px; letter-spacing: .16em; color: var(--gold-300); font-weight: 700; }
.stance__row { display: flex; align-items: center; gap: 6px; }
.stance__track { flex: 1; height: 8px; border-radius: 4px; background: #02060d; border: 1px solid #000; position: relative; }
.stance__track::after { content: ''; position: absolute; left: 50%; top: -3px; width: 2px; height: 14px; background: var(--emerald); }
.stance__track i { position: absolute; top: -4px; left: 50%; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--gold-300); border: 2px solid var(--ink); transition: left .1s, background .2s; }
.meter { height: 6px; border-radius: 3px; background: #02060d; overflow: hidden; }
.meter i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #4cc3ff, #9be8ff); transition: width .1s; }
.meter.low i { background: linear-gradient(90deg, #ff6b6b, #ffb199); }

.power { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 12px; border-radius: 16px; background: rgba(6,15,31,.82); border: 2px solid rgba(232,181,58,.6); transition: opacity .2s; pointer-events: none; }
.power.dim { opacity: .6; }
.power__lbl { font-size: 9px; letter-spacing: .12em; color: rgba(255,246,224,.55); }
.power__bar { position: relative; width: 26px; height: min(38vh, 230px); border-radius: 13px; background: #02060d; border: 2px solid var(--ink); overflow: hidden; }
.power__zone { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(135deg, rgba(40, 220, 130, .6) 0 6px, rgba(40, 220, 130, .32) 6px 12px); border-top: 2px solid #5dffa8; border-bottom: 2px solid #5dffa8; }
.power__fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(0deg, var(--gold-700), var(--gold-300)); opacity: .85; }
.power__mark { position: absolute; left: -2px; right: -2px; height: 4px; margin-bottom: -2px; bottom: 0; background: #fff; box-shadow: 0 0 8px #fff; border-radius: 2px; }
.cancel { width: 190px; display: flex; justify-content: flex-end; }
.cancel .btn { opacity: 0; pointer-events: none; transition: opacity .2s; }
.cancel .btn.show { opacity: 1; pointer-events: auto; }

.overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(2, 8, 18, .72); backdrop-filter: blur(3px); }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px); opacity: 0; z-index: 100; padding: 12px 22px; border-radius: 14px; font-weight: 600; background: var(--burgundy); border: 2px solid var(--ink); transition: .25s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.rotate-hint { display: none; position: fixed; inset: 0; z-index: 200; background: rgba(2,8,18,.94); place-items: center; text-align: center; font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--gold-300); padding: 30px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .home { grid-template-columns: 1fr; justify-items: center; text-align: center; padding-top: 0; }
  .home__board canvas { width: min(62vw, 300px); }
  .menu { align-items: center; }
  .menu__row { justify-content: center; }
  .sub { margin-left: auto; margin-right: auto; }
  .btn--xl { font-size: 22px; padding: 16px 32px; }
}
@media (max-width: 720px) {
  .scoreboard__item { min-width: 0; padding: 2px 8px; }
  .scoreboard__item b { font-size: 15px; max-width: 80px; }
  .scoreboard__item--score b { font-size: 18px; }
  .hud__brand .wordmark { display: none; }
  .field-row { flex-direction: column; gap: 0; }
  .stance { width: 150px; }
  .stance .btn small, .cancel .btn small, .hint kbd:not(.k-always) { display: none; }
  .cancel { width: 110px; }
  .hint { bottom: 12px; font-size: 12px; }
}
@media (max-height: 520px) {
  .stance__title { display: none; }
  .darts { top: 62px; }
  .phase-banner { top: 58px; }
}
@media (orientation: portrait) and (max-width: 720px) {
  #screen-game.active ~ .rotate-hint, body.in-game .rotate-hint { display: grid; }
}
@media (prefers-reduced-motion: reduce) {
  .home__board canvas { animation: none; }
}

/* ---------- Khung "Cách phóng" ---------- */
.brandbar .js-sound { margin-left: auto; }
.tips { position: absolute; left: 14px; bottom: 168px; width: 252px; padding: 10px 12px 12px; border-radius: 16px; background: rgba(6,15,31,.84); border: 2px solid rgba(232,181,58,.6); pointer-events: none; }
.tips__title { font-size: 10px; letter-spacing: .16em; color: var(--gold-300); font-weight: 700; margin-bottom: 6px; }
.tips ol { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.tips li { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; line-height: 1.35; opacity: .62; transition: opacity .2s, background .2s; padding: 4px 6px; margin: 0 -6px; border-radius: 10px; }
.tips li b { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 12px; color: var(--ink); background: rgba(232,181,58,.55); border: 2px solid var(--ink); }
.tips em { font-style: normal; font-weight: 700; color: var(--gold-300); }
.tips kbd { font-family: var(--font-display); font-weight: 800; font-size: 11px; padding: 0 6px; border-radius: 5px; color: var(--ink); background: var(--gold-300); }
.tips[data-step="1"] li[data-step="1"], .tips[data-step="2"] li[data-step="2"], .tips[data-step="3"] li[data-step="3"] { opacity: 1; background: rgba(232,181,58,.16); }
.tips[data-step="1"] li[data-step="1"] b, .tips[data-step="2"] li[data-step="2"] b, .tips[data-step="3"] li[data-step="3"] b { background: linear-gradient(180deg, var(--gold-300), var(--gold-500)); }
.t-touch { display: none; }
.is-touch .t-touch { display: inline; }
.is-touch .t-mouse { display: none; }
@media (max-width: 720px), (max-height: 540px) { .tips { width: 206px; bottom: 150px; padding: 8px 10px; } .tips li { font-size: 11px; } .tips__title { display: none; } }
@media (max-width: 720px) and (max-height: 420px) { .tips { display: none; } }
