[hidden] { display: none !important; }
:root {
  --p0: #2563eb; --p1: #e11d48; --p2: #f97316; --p3: #111827;
  --glass: rgba(255, 255, 255, .86); --ink: #17212b; --muted: #5b6b78; --accent: #16a34a; --shadow: 0 8px 24px rgba(12, 40, 60, .25);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; color: var(--ink); background: #9fd4ee; }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }
button { font: inherit; cursor: pointer; border: none; }
input { font: inherit; }

/* ---------- landing ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(10, 40, 60, .15), rgba(10, 40, 60, .55)); z-index: 20; }
.landing-card { width: min(560px, 94vw); background: var(--glass); backdrop-filter: blur(10px); border-radius: 22px; padding: 28px 30px 18px; box-shadow: var(--shadow); text-align: center; }
.logo { font-size: 64px; font-weight: 900; letter-spacing: 10px; background: linear-gradient(135deg, #15803d, #0ea5e9 60%, #f59e0b); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1; }
.tag { margin: 6px 0 18px; color: var(--muted); }
.name-row input, .join-row input { width: 100%; padding: 10px 14px; border-radius: 12px; border: 2px solid #dbe4ea; background: #fff; text-align: center; }
.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.big { padding: 16px 8px; border-radius: 16px; font-weight: 700; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 4px 0 rgba(0, 0, 0, .18); transition: transform .1s; }
.big span { font-size: 30px; }
.big:hover { transform: translateY(-2px); }
.big:active { transform: translateY(2px); box-shadow: none; }
.big.play { background: linear-gradient(160deg, #22c55e, #15803d); }
.big.online { background: linear-gradient(160deg, #38bdf8, #0369a1); }
.big.local { background: linear-gradient(160deg, #fbbf24, #d97706); }
.big.sel { outline: 4px solid #fff; outline-offset: -6px; }
.setup { text-align: left; background: #fff; border-radius: 14px; padding: 10px 14px; margin-bottom: 12px; }
.setup h3 { margin: 4px 0 8px; font-size: 15px; }
.seat { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid #eef2f5; }
.seat .av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; }
.seat select { flex: 1; padding: 6px; border-radius: 8px; border: 1px solid #cfd8de; }
.seat .x { background: none; font-size: 16px; color: #999; }
.ghost { background: none; color: #0369a1; padding: 6px 0; font-weight: 600; }
.cta { display: block; width: 100%; padding: 12px; border-radius: 12px; background: linear-gradient(160deg, #22c55e, #15803d); color: #fff; font-weight: 800; font-size: 17px; margin-top: 8px; box-shadow: 0 4px 0 #14532d; }
.cta:active { transform: translateY(2px); box-shadow: none; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; }
.join-row button { padding: 0 18px; border-radius: 12px; background: #0369a1; color: #fff; font-weight: 700; }
.fine { font-size: 11px; color: var(--muted); margin: 14px 0 0; }

/* ---------- HUD ---------- */
#hud > * { position: fixed; z-index: 5; }
.topbar { top: 10px; left: 10px; right: 10px; display: flex; align-items: center; gap: 10px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { background: var(--glass); padding: 8px 16px; border-radius: 14px; font-weight: 900; letter-spacing: 4px; color: #15803d; box-shadow: var(--shadow); }
.brand small { letter-spacing: 1px; color: var(--muted); font-weight: 600; }
.chip { background: #0369a1; color: #fff; padding: 8px 14px; border-radius: 14px; font-weight: 700; letter-spacing: 2px; cursor: pointer; box-shadow: var(--shadow); }
.tools { margin-left: auto; display: flex; gap: 6px; }
.tool { width: 42px; height: 42px; border-radius: 12px; background: var(--glass); box-shadow: var(--shadow); font-size: 19px; }
.tool.on { background: #cffafe; outline: 2px solid #06b6d4; }

body.ingame #stage { left: 270px; right: 330px; }
.left { top: 66px; left: 10px; bottom: 10px; width: 250px; display: flex; flex-direction: column; gap: 10px; }
.side { top: 66px; right: 10px; bottom: 10px; width: 310px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.panel { background: var(--glass); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 14px; }
.ptitle { font-size: 11px; font-weight: 800; letter-spacing: 1.5px; color: var(--muted); text-transform: uppercase; margin-bottom: 6px; }
.players { display: flex; flex-direction: column; gap: 8px; }
.pcard { background: var(--glass); border-radius: 16px; padding: 10px 12px; box-shadow: var(--shadow); display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: center; border: 3px solid transparent; transition: transform .2s, border-color .2s; }
.pcard.turn { border-color: var(--c); transform: translateX(6px); }
.pcard .av { width: 44px; height: 44px; border-radius: 50%; background: var(--c); display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 18px; position: relative; }
.pcard.turn .av::after { content: ''; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid var(--c); animation: ping 1.4s infinite; }
@keyframes ping { 0% { transform: scale(.9); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }
.pcard .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .st { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.pcard .sc { font-size: 26px; font-weight: 900; min-width: 44px; text-align: right; flex-shrink: 0; }
.pcard > div { min-width: 0; }
.pcard .thinking { font-size: 11px; color: var(--c); font-weight: 700; }

.feed { flex: 1; min-height: 120px; display: flex; flex-direction: column; background: var(--glass); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; text-align: left; padding-top: 10px; }
.feed .ptitle { padding: 0 12px; }
.feed ol { flex: 1; list-style: none; margin: 0; padding: 0 10px 8px; overflow-y: auto; font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.feed li { padding: 3px 6px; border-radius: 8px; }
.feed li b { color: var(--c); }
.feed li.hl { background: #fef9c3; }
.feed li { cursor: pointer; }
.feed li .sub { font-size: 11.5px; color: #92400e; padding-left: 10px; }
.preview { border: 3px solid #fff; background: #0f172a; color: #fff; }
.preview .pts { font-size: 22px; font-weight: 900; color: #fde047; }
.preview .bad { color: #fca5a5; }
.preview .rank { color: #a5f3fc; margin-top: 4px; }
.preview { display: flex; flex-direction: column; }
.preview .pv-body { flex: 1; overflow-y: auto; font-size: 13px; }
.preview .pv-actions { display: flex; gap: 8px; margin-top: 8px; flex-shrink: 0; }
.preview .pv-actions .cta { margin: 0; flex: 2; padding: 12px 6px; }
.preview .cancel { flex: 1; background: #334155; color: #e2e8f0; border-radius: 12px; font-weight: 700; }
.pcard .lvl { font-size: 10px; font-weight: 800; background: #e2e8f0; color: #475569; border-radius: 6px; padding: 1px 5px; vertical-align: 2px; }
.preview .pv-title { color: #cbd5e1; font-size: 12px; margin-bottom: 2px; }
.tally { margin-top: 8px; font-size: 12.5px; }
.confirm { position: fixed; z-index: 28; left: 50%; bottom: 24px; transform: translateX(-50%); background: linear-gradient(160deg, #22c55e, #15803d); color: #fff; font-weight: 800; font-size: 17px; padding: 12px 26px; border-radius: 999px; box-shadow: 0 4px 0 #14532d, var(--shadow); }
.feed li.chatmsg { background: #e0f2fe; }
#chat input { width: 100%; border: none; border-top: 1px solid #e2e8f0; padding: 9px 12px; background: #fff; }

.turn { border: 3px solid transparent; }
.turn.mine { border-color: #22c55e; animation: glow 1.6s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, .3), var(--shadow); } }
.turn .who { font-size: 13px; font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; color: var(--c, #64748b); }
.turn.mine .who { color: #16a34a; font-size: 18px; }
.turn .row { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.turn .how { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.hex { width: 64px; min-width: 64px; height: 72px; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); background: var(--c); display: grid; place-items: center; font-size: 26px; color: #fff; text-shadow: 0 2px 4px rgba(0, 0, 0, .3); }
.hand-info b { font-size: 16px; }
.upcoming { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; font-size: 11.5px; }
.upcoming span { background: #f1f5f9; padding: 2px 7px; border-radius: 8px; }

.coach-head { display: flex; justify-content: space-between; align-items: center; }
.coach-head .x { background: none; color: var(--muted); font-size: 16px; }
.advice .phase { font-size: 12px; background: #f0fdfa; border-left: 4px solid #14b8a6; border-radius: 8px; padding: 6px 8px; margin-bottom: 8px; }
.advice ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.advice li { background: #fff; border: 2px solid #a5f3fc; border-radius: 12px; padding: 8px; cursor: pointer; font-size: 12.5px; transition: transform .1s; }
.advice li:first-child { border-color: #06b6d4; box-shadow: 0 0 0 3px rgba(6, 182, 212, .15); }
.advice li:hover { transform: translateX(-3px); border-color: #0891b2; }
.advice .top { display: flex; align-items: center; gap: 8px; }
.advice .top b { flex: 1; }
.advice .rk { width: 24px; height: 24px; min-width: 24px; border-radius: 50%; background: #06b6d4; color: #fff; font-weight: 900; display: grid; place-items: center; }
.advice .pp { font-weight: 900; font-size: 15px; color: #0e7490; white-space: nowrap; }
.advice .bar { display: flex; height: 7px; background: #f1f5f9; border-radius: 4px; overflow: hidden; margin: 6px 0 2px; }
.advice .bar .now { background: #0891b2; }
.advice .bar .later { background: #67e8f9; }
.advice .val { font-size: 11px; color: var(--muted); }
.advice .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.advice .why { font-size: 11px; border-radius: 8px; padding: 2px 7px; background: #f1f5f9; }
.advice .why.castle { background: #e0e7ff; color: #3730a3; }
.advice .why.mission { background: #f3e8ff; color: #6b21a8; }
.advice .why.farm { background: #ecfccb; color: #3f6212; }
.advice .why.settle { background: #ffedd5; color: #9a3412; }
.advice .why.bad { background: #fee2e2; color: #b91c1c; }
.advice .note { font-size: 11px; color: var(--muted); margin-top: 6px; }
.sec { margin-top: 10px; }
.sec .lab { font-size: 10.5px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.turn .do { margin-top: 8px; font-size: 13px; background: #f0fdf4; border-radius: 8px; padding: 6px 8px; }
.turn .aside { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.turn .last { font-size: 12.5px; background: #f8fafc; border-left: 4px solid var(--c); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.coach-hint { margin-top: 10px; width: 100%; background: #ecfeff; color: #0e7490; border: 1px dashed #67e8f9; border-radius: 10px; padding: 7px; font-weight: 700; font-size: 12.5px; }
.mcard { background: linear-gradient(160deg, #ecfeff, #d1fae5); border: 2px solid #34d399; border-radius: 12px; padding: 6px 8px; font-size: 12px; margin-top: 6px; }
.mcard.no { background: #fff7ed; border-color: #fdba74; }
.mcard b { display: block; font-size: 12.5px; }
.mcard .ok { color: #15803d; font-weight: 800; }
.mcard .bad { color: #c2410c; font-weight: 800; }
.legend-panel { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); padding: 8px 12px; }
.legend-panel i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -2px; }

.labels { inset: 0; pointer-events: none; z-index: 4 !important; }
.lbl { position: fixed; transform: translate(-50%, -50%); background: rgba(255, 255, 255, .92); color: #17212b; border-radius: 999px; padding: 1px 7px; font-size: 12px; font-weight: 900; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); white-space: nowrap; }
.lbl.zero { background: rgba(255, 255, 255, .55); color: #64748b; font-weight: 700; }
.lbl.best { background: #06b6d4; color: #fff; font-size: 14px; padding: 2px 9px; }
.lbl.best::before { content: attr(data-rank) '  '; opacity: .8; }

.tip { position: fixed; z-index: 30; pointer-events: none; background: rgba(23, 33, 43, .94); color: #fff; border-radius: 10px; padding: 7px 10px; font-size: 12.5px; max-width: 260px; transform: translate(-50%, -100%); }
.tip .rank { margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(255,255,255,.2); color: #a5f3fc; }
.tip .pts { font-size: 18px; font-weight: 900; color: #fde047; }
.tip .bad { color: #fca5a5; }
.toasts { position: fixed; left: 10px; bottom: 10px; width: 250px; z-index: 25; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toasts:empty { display: none; }
.toast { background: #fff; border-radius: 12px; padding: 8px 16px; box-shadow: var(--shadow); font-weight: 700; animation: tin .25s ease-out, tout .4s ease-in 2.4s forwards; border-left: 6px solid var(--c, #16a34a); }
@keyframes tin { from { transform: translateY(-12px); opacity: 0; } }
@keyframes tout { to { transform: translateY(-12px); opacity: 0; } }
.float { position: fixed; z-index: 26; pointer-events: none; font-weight: 900; font-size: 26px; color: #fff; -webkit-text-stroke: 1.5px rgba(0, 0, 0, .45); animation: rise 1.3s ease-out forwards; transform: translate(-50%, -50%); }
.float.card { font-size: 15px; background: rgba(23, 33, 43, .88); color: #fff; -webkit-text-stroke: 0; padding: 4px 12px; border-radius: 999px; animation-duration: 2.2s; }
.verdict { text-align: center; color: var(--muted); margin: 0 0 8px; }
@keyframes rise { to { transform: translate(-50%, -160%); opacity: 0; } }

dialog { border: none; border-radius: 20px; padding: 22px 26px; box-shadow: var(--shadow); max-width: 680px; width: 94vw; }
dialog::backdrop { background: rgba(10, 30, 45, .55); backdrop-filter: blur(2px); }
.rules-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 14px; margin-bottom: 12px; }
.rules-grid > div { background: #f8fafc; border-radius: 12px; padding: 10px; }
#final h2 { text-align: center; font-size: 30px; margin: 0 0 6px; }
.podium { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.prow { display: grid; grid-template-columns: 34px 120px 1fr 54px; gap: 8px; align-items: center; }
.prow .av { width: 30px; height: 30px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-weight: 900; }
.bar { display: flex; height: 22px; border-radius: 8px; overflow: hidden; background: #f1f5f9; }
.bar i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; justify-content: center; margin: 6px 0; }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 4px; }
.confetti { position: fixed; top: -10px; width: 10px; height: 14px; z-index: 40; animation: fall linear forwards; pointer-events: none; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 1000px) {
  body.ingame #stage { left: 0; right: 0; top: 118px; bottom: 200px; }
  .brand small, #t-camera { display: none; }
  .brand { padding: 8px 10px; letter-spacing: 2px; font-size: 13px; }
  .tool { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }
  .tools { gap: 4px; }
  .left { top: 58px; bottom: auto; width: auto; right: 10px; }
  .players { flex-direction: row; gap: 6px; }
  .pcard { flex: 1; min-width: 0; padding: 6px 8px; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 6px; border-radius: 12px; }
  .pcard.turn { transform: none; }
  .pcard .av { width: 30px; height: 30px; font-size: 14px; }
  .pcard .sc { font-size: 20px; min-width: 0; }
  .pcard .st { display: none; }
  .feed, .legend-panel { display: none; }
  .side { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; height: 190px; flex-direction: row; overflow-x: auto; scroll-snap-type: x mandatory; gap: 8px; }
  .side .panel { min-width: calc(100vw - 40px); scroll-snap-align: start; overflow-y: auto; }
  .toasts { left: 8px; right: 8px; width: auto; bottom: 204px; }
  body.selecting .toasts { display: none; }
  .preview { position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); height: 190px; z-index: 30; min-width: 0 !important; }
  .pcard .nm { font-size: 13px; }
  #tip { display: none !important; }
  .mode-grid { grid-template-columns: 1fr; }
}

@media (max-height: 800px) and (min-width: 1001px) {
  .advice .note, .advice .val { display: none; }
  .turn .how { font-size: 11.5px; }
}
