* { box-sizing: border-box; }
:root {
  --ink: #1b1224; --ink2: #120c18; --panel: rgba(28, 19, 36, 0.9); --panel2: rgba(44, 30, 54, 0.92);
  --gold: #d9a441; --gold2: #f3d58a; --ivory: #f6efe0; --muted: #bdb1c4; --saffron: #e98a2b; --teal: #2a8a86;
  --ruby: #b3322a; --green: #5aa55a; --line: rgba(217, 164, 65, 0.35);
  --bs: 560px; --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', 'Noto Sans', 'Noto Sans Thai', 'Leelawadee UI',
    'Hiragino Sans', 'Noto Sans JP', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --head: 'Baloo 2', var(--font);
}
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--ivory); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

#bg { position: fixed; inset: 0; background: radial-gradient(ellipse at 50% 40%, #3a2440 0%, #1b1224 70%); }
#bg.img { background: linear-gradient(180deg, rgba(20, 12, 26, 0.35), rgba(20, 12, 26, 0.72)), url('assets/bg_palace.webp') center / cover no-repeat, #1b1224; }
#bg.img::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 45%, rgba(10, 5, 14, 0.55) 100%); }
#app { position: fixed; inset: 0; }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 60; width: 100%; height: 100%; }

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.9); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes bob { 50% { transform: translateY(-3px) rotate(-1deg); } }
@keyframes breathe { 50% { transform: scale(1.03); } }
@keyframes spin { to { transform: rotate(360deg) } }
@keyframes shake { 20%, 60% { transform: translateX(-4px) } 40%, 80% { transform: translateX(4px) } }
@keyframes glow { 50% { box-shadow: 0 0 0 2px var(--gold2), 0 0 18px rgba(243, 213, 138, .6); } }
@keyframes think { 0%, 100% { opacity: .35 } 50% { opacity: 1 } }

/* ---------------------------------------------------------------- game table */
#table { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 18px; padding: 12px; }
#board-col { display: flex; flex-direction: column; gap: 8px; width: var(--bs); flex: none; }
#board-box { position: relative; width: var(--bs); height: var(--bs); border-radius: 6px; overflow: visible;
  box-shadow: 0 0 0 3px #2b1d33, 0 0 0 5px var(--gold), 0 14px 40px rgba(0, 0, 0, 0.55); }
#board { display: block; touch-action: none; border-radius: 4px; cursor: pointer; }
#board-note { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 2px solid var(--gold);
  padding: 10px 18px; border-radius: 14px; font-weight: 800; font-size: 20px; text-align: center; animation: pop .2s ease; pointer-events: none; }

.pbar { position: relative; display: flex; align-items: center; gap: 10px; height: 52px; padding: 4px 6px; border-radius: 12px; background: rgba(20, 12, 26, 0.55); }
.pbar.turn { box-shadow: inset 0 0 0 2px rgba(243, 213, 138, 0.55); }
.avatar { position: relative; width: 44px; height: 44px; flex: none; border-radius: 50%; background: #3a2a44; box-shadow: 0 0 0 2px var(--gold);
  display: grid; place-items: center; overflow: hidden; }
.avatar img { width: 118%; height: 118%; object-fit: cover; object-position: 50% 20%; }
.avatar img[src=""], .avatar img:not([src]) { display: none; }
.avatar .glyph { font-size: 26px; line-height: 1; }
.avatar.thinking { animation: breathe 1s ease-in-out infinite; box-shadow: 0 0 0 2px var(--gold2), 0 0 14px rgba(243, 213, 138, .7); }
.pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.pname { font-family: var(--head); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.psub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.caps { display: flex; align-items: center; height: 16px; gap: 0; }
.caps img { width: 16px; height: 16px; margin-right: -5px; }
.caps b { margin-left: 8px; font-size: 12px; color: var(--muted); }
.clock { font-family: var(--head); font-weight: 800; font-size: 24px; min-width: 88px; text-align: center; padding: 2px 10px; border-radius: 10px;
  background: #2a1f30; color: #d9ced9; font-variant-numeric: tabular-nums; }
.clock.run { background: var(--ivory); color: #1b1224; }
.clock.low { background: var(--ruby); color: #fff; }
.bubble { pointer-events: none; position: absolute; left: 58px; bottom: 50px; max-width: min(320px, 80vw); background: var(--ivory); color: #2a1a2e; font-weight: 700; font-size: 14px;
  padding: 7px 12px; border-radius: 14px; z-index: 5; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); animation: pop .18s ease; line-height: 1.25; }
#bar-top .bubble { bottom: auto; top: 50px; }
.bubble::after { content: ''; position: absolute; left: 14px; bottom: -7px; border: 7px solid transparent; border-top-color: var(--ivory); border-bottom: 0; }
#bar-top .bubble::after { bottom: auto; top: -7px; border-top: 0; border-bottom: 7px solid var(--ivory); }

#side { width: clamp(250px, 26vw, 340px); height: min(calc(var(--bs) + 120px), 100%); display: flex; flex-direction: column; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px; }
#side-head { display: flex; align-items: center; gap: 8px; }
#mode-title { flex: 1; font-family: var(--head); font-weight: 800; font-size: 18px; color: var(--gold2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: rgba(255, 255, 255, 0.08); border-radius: 10px; width: 38px; height: 38px; font-size: 20px; cursor: pointer; flex: none; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.16); }
.opening { font-size: 13px; color: var(--muted); min-height: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opening b { color: var(--gold2); }
.moves { flex: 1; min-height: 60px; overflow-y: auto; background: rgba(0, 0, 0, 0.18); border-radius: 10px; padding: 4px; font-size: 15px;
  display: grid; grid-template-columns: 34px 1fr 1fr; align-content: start; gap: 1px 2px; font-variant-numeric: tabular-nums; }
.moves .n { color: var(--muted); text-align: right; padding: 3px 6px 3px 0; font-size: 13px; }
.moves .mv { padding: 3px 6px; border-radius: 6px; cursor: pointer; font-weight: 700; white-space: nowrap; }
.moves .mv:hover { background: rgba(255, 255, 255, 0.08); }
.moves .mv.cur { background: var(--gold); color: #24160c; }
.moves .mv i { font-style: normal; font-size: 12px; margin-left: 3px; }
.moves .empty { grid-column: 1 / -1; color: var(--muted); font-size: 13px; padding: 8px; text-align: center; }
.cls-best { color: #7fd1a8; } .cls-good { color: #b7d98a; } .cls-inaccuracy { color: #f0c860; } .cls-mistake { color: #f09a40; } .cls-blunder { color: #ff6b5b; }
.coach { background: rgba(243, 213, 138, 0.12); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; line-height: 1.3; animation: pop .2s ease; }
.coach.bad { background: rgba(179, 50, 42, 0.25); border-color: rgba(255, 107, 91, 0.5); }
.coach.good { background: rgba(90, 165, 90, 0.2); border-color: rgba(127, 209, 168, 0.5); }
.coach-act { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.coach-act .btn { font-size: 14px; padding: 5px 12px; }
.nav { display: flex; gap: 4px; }
.nav button { flex: 1; border: 0; border-radius: 8px; background: rgba(255, 255, 255, 0.08); padding: 6px 0; cursor: pointer; font-size: 15px; }
.nav button:hover { background: rgba(255, 255, 255, 0.16); }
.nav .nav-menu { display: none; }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.controls .btn { font-size: 14px; padding: 8px 4px; border-radius: 10px; }
.controls .btn small { display: block; font-size: 11px; opacity: 0.8; font-weight: 700; }
.pz-goal { font-family: var(--head); font-size: 20px; font-weight: 800; color: var(--gold2); line-height: 1.2; }
.pz-meta { font-size: 13px; color: var(--muted); }
#review-box canvas { width: 100%; height: 90px; display: block; background: rgba(0, 0, 0, 0.25); border-radius: 8px; cursor: pointer; }
.acc { display: flex; justify-content: space-between; font-size: 13px; margin-top: 4px; color: var(--muted); }
.acc b { color: var(--ivory); font-size: 16px; }

/* promotion picker */
#promo { position: absolute; z-index: 10; display: flex; flex-direction: column; background: var(--ivory); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6); overflow: hidden; animation: pop .15s ease; }
#promo button { border: 0; background: transparent; padding: 0; cursor: pointer; display: block; }
#promo button:hover { background: rgba(217, 164, 65, 0.4); }
#promo canvas { display: block; }

/* ---------------------------------------------------------------- overlays & panels */
.overlay { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 20;
  background: rgba(12, 7, 16, 0.62); animation: fade .2s ease; padding: 12px; }
.overlay.top { z-index: 40; }
.overlay.menu { background: transparent; }
.loader { text-align: center; font-size: 20px; color: var(--gold2); font-family: var(--head); }
.spin { width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 50%; border: 5px solid rgba(217, 164, 65, .25); border-top-color: var(--gold2); animation: spin 1s linear infinite; }
.modal, .panel { background: linear-gradient(165deg, #2e1f38, #1a1120 70%); border: 2px solid var(--gold); border-radius: 22px;
  box-shadow: 0 0 0 5px rgba(20, 12, 26, .85), 0 20px 60px rgba(0, 0, 0, .6); padding: 18px 22px; width: min(520px, 100%); max-height: 100%;
  overflow: auto; animation: pop .2s ease; text-align: center; position: relative; }
.modal.wide { width: min(760px, 100%); }
.panel { width: min(1100px, 100%); max-height: min(720px, 100%); text-align: left; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.panel-head h2 { flex: 1; text-align: left; }
h2 { margin: 0 0 6px; font-family: var(--head); font-size: 30px; color: var(--gold2); line-height: 1.1; }
h3 { margin: 0 0 6px; font-family: var(--head); color: var(--gold2); font-size: 18px; }
.sub { margin: 4px 0 10px; font-size: 16px; color: #ddd2e2; line-height: 1.3; }
.sub.small { font-size: 13px; color: var(--muted); }
.lbl { margin: 10px 0 6px; font-weight: 800; color: var(--gold2); font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }
.actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; margin: 10px auto 4px; width: min(320px, 100%); }
.err { color: #ff8a7a; font-weight: 700; margin: 6px 0 0; }
.count { color: var(--muted); font-weight: 800; }

.btn { font-weight: 800; font-size: 17px; color: #fff; border: 0; border-radius: 14px; padding: 10px 20px; cursor: pointer; line-height: 1.15;
  background: linear-gradient(#e89a3c, #b8641c); box-shadow: 0 3px 0 #6b3a10, inset 0 1px 0 rgba(255, 230, 190, .35);
  transition: transform .08s ease, filter .12s; text-shadow: 0 1px 0 rgba(0, 0, 0, .35); position: relative; }
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #6b3a10; }
.btn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: default; transform: none; }
.btn.gold { background: linear-gradient(#f0c65e, #b98a1f); color: #2a1a06; text-shadow: 0 1px 0 rgba(255, 240, 200, .5); box-shadow: 0 3px 0 #6a4c0c; }
.btn.jade { background: linear-gradient(#3aa39e, #1e6b68); box-shadow: 0 3px 0 #0e3b39; }
.btn.red { background: linear-gradient(#cf4a3e, #8e2219); box-shadow: 0 3px 0 #4e0f0a; }
.btn.dark { background: linear-gradient(#4a3656, #2e2036); box-shadow: 0 3px 0 #150d1a, inset 0 0 0 1px var(--line); }
.btn.big { font-size: 20px; padding: 12px 26px; }
.btn.icon { padding: 10px 14px; }
.btn .dot, .dot { position: absolute; top: -3px; right: -3px; width: 12px; height: 12px; border-radius: 50%; background: var(--ruby); box-shadow: 0 0 0 2px var(--ink); }

.choice { display: flex; flex-wrap: wrap; gap: 6px; }
.choice button { border: 0; border-radius: 12px; padding: 8px 12px; cursor: pointer; font-weight: 800; background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px var(--line); font-size: 15px; }
.choice button small { display: block; font-size: 11px; color: var(--muted); font-weight: 700; }
.choice button.on { background: var(--gold); color: #24160c; box-shadow: none; }
.choice button.on small { color: #4a3210; }
.toggle { display: flex; gap: 10px; align-items: center; justify-content: flex-start; margin: 12px 0 0; font-weight: 700; cursor: pointer; text-align: left; }
.toggle input { width: 20px; height: 20px; accent-color: var(--gold); flex: none; }

/* ---------------------------------------------------------------- menu */
.menu-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 340px); gap: 28px; width: min(1100px, 100%); max-height: 100%; overflow: auto; align-items: center; padding: 6px; }
.menu-main { display: flex; flex-direction: column; gap: 14px; }
.logo { display: flex; flex-direction: column; line-height: 0.95; }
.logo .l1 { font-family: var(--head); font-weight: 800; font-size: clamp(44px, 7vw, 76px); color: var(--gold2);
  text-shadow: 0 3px 0 #7a4a12, 0 0 30px rgba(243, 213, 138, 0.35); letter-spacing: 0.01em; }
.logo .l2 { font-family: var(--head); font-weight: 700; font-size: clamp(17px, 2.2vw, 24px); color: var(--ivory); opacity: 0.9; margin-top: 6px; }
.profile-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: rgba(20, 12, 26, 0.7); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 15px; }
.chip b { color: var(--gold2); }
.modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mode { border: 0; cursor: pointer; text-align: left; border-radius: 18px; padding: 14px 16px; display: grid; grid-template-columns: 48px minmax(0, 1fr); grid-template-rows: auto auto; min-width: 0; overflow-wrap: anywhere;
  column-gap: 12px; align-items: center; background: linear-gradient(160deg, rgba(58, 38, 70, 0.92), rgba(30, 20, 38, 0.92));
  box-shadow: inset 0 0 0 1.5px var(--line), 0 8px 22px rgba(0, 0, 0, 0.3); transition: transform .1s ease, box-shadow .15s; }
.mode:hover { transform: translateY(-2px); box-shadow: inset 0 0 0 2px var(--gold), 0 12px 26px rgba(0, 0, 0, 0.35); }
.mode .mi { grid-row: span 2; font-size: 38px; text-align: center; }
.mode b { font-family: var(--head); font-size: 21px; line-height: 1.1; }
.mode small { color: var(--muted); font-size: 13px; font-weight: 700; }
#mode-ai { background: linear-gradient(160deg, rgba(233, 138, 43, 0.95), rgba(150, 70, 20, 0.95)); }
#mode-ai small { color: #ffe6c8; }
.btn.continue { display: flex; flex-direction: column; align-items: flex-start; text-align: left; animation: glow 2.4s ease-in-out infinite; }
.btn.continue small { font-size: 13px; opacity: 0.85; }
.menu-row { display: flex; flex-wrap: wrap; gap: 8px; }
.menu-row .btn { font-size: 15px; padding: 8px 14px; }
.menu-side { display: flex; flex-direction: column; gap: 14px; }
.court-card { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 12px; cursor: pointer; }
.court-portrait { position: relative; width: 110px; height: 110px; flex: none; }
.court-portrait img { width: 110px; height: 110px; object-fit: contain; animation: bob 2.6s ease-in-out infinite; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .45)); }
.court-portrait .bubble { left: 60px; bottom: 96px; top: auto; width: max-content; max-width: 220px; }
.court-info { display: flex; flex-direction: column; min-width: 0; }
.court-info small { color: var(--muted); font-weight: 700; }
.court-info b { font-family: var(--head); font-size: 22px; color: var(--gold2); line-height: 1.1; }
.court-info span { font-size: 13px; color: #ddd2e2; }
.quests-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; }
.quest { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; margin: 8px 0; font-size: 14px; }
.quest .qbar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.quest .qbar i { display: block; height: 100%; background: var(--gold); }
.quest.done { opacity: 0.7; }
.quest.done .qbar i { background: var(--green); }
.fact { font-size: 13px; color: var(--muted); line-height: 1.35; margin: 0; font-style: italic; }

/* ---------------------------------------------------------------- setup / puzzles / result */
.opp-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.opp { border: 0; cursor: pointer; border-radius: 14px; padding: 6px 4px 8px; background: rgba(255, 255, 255, 0.06); box-shadow: inset 0 0 0 1px var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.opp img { width: 72px; height: 72px; object-fit: contain; }
.opp .ph { width: 72px; height: 72px; display: grid; place-items: center; font-size: 34px; }
.opp b { font-family: var(--head); font-size: 15px; line-height: 1.1; }
.opp small { font-size: 11px; color: var(--muted); font-weight: 700; }
.opp .crowns { position: absolute; top: 4px; right: 6px; font-size: 13px; letter-spacing: -2px; }
.opp.on { background: rgba(217, 164, 65, 0.25); box-shadow: inset 0 0 0 2px var(--gold); }
.opp-detail { display: flex; gap: 14px; align-items: center; margin: 10px 0; min-height: 64px; background: rgba(0, 0, 0, 0.2); border-radius: 14px; padding: 8px 12px; }
.opp-detail b { font-family: var(--head); font-size: 20px; color: var(--gold2); }
.opp-detail p { margin: 2px 0 0; font-size: 14px; color: #ddd2e2; }
.setup-row { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; }
.pz-stats { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 4px 0 12px; }
.pz-stats .chip { font-size: 16px; }
.pz-modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pz-modes .mode { grid-template-columns: 40px 1fr; padding: 10px 12px; }
.pz-modes .mode .mi { font-size: 28px; }
.pz-modes .mode b { font-size: 17px; }
.result { width: min(460px, 100%); }
.res-icon { font-size: 54px; line-height: 1; animation: bob 1.6s ease-in-out infinite; }
.res-body { display: flex; flex-direction: column; gap: 6px; align-items: center; font-size: 15px; }
.res-body .row { display: flex; gap: 8px; align-items: center; }
.res-body .delta { font-weight: 800; }
.res-body .up { color: #7fd1a8; } .res-body .down { color: #ff8a7a; }
.res-body .unlock { background: rgba(217, 164, 65, 0.18); border: 1px solid var(--line); padding: 4px 12px; border-radius: 999px; }
textarea, input[readonly], #pgn-in { width: 100%; font: 13px/1.35 ui-monospace, Menlo, Consolas, monospace; background: #120c18; color: var(--ivory);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px; resize: vertical; -webkit-user-select: text; user-select: text; }
input[readonly] { margin-top: 6px; }

/* style / trophies / stats / rules / settings / lang */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { border: 0; cursor: pointer; border-radius: 14px; padding: 6px; background: rgba(255, 255, 255, 0.06); box-shadow: inset 0 0 0 1px var(--line);
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 132px; position: relative; }
.swatch canvas { width: 120px; height: 120px; border-radius: 8px; display: block; }
.swatch b { font-size: 14px; }
.swatch small { font-size: 11px; color: var(--muted); line-height: 1.2; text-align: center; }
.swatch.on { box-shadow: inset 0 0 0 2px var(--gold); background: rgba(217, 164, 65, 0.2); }
.swatch.locked canvas { filter: grayscale(0.85) brightness(0.55); }
.swatch .lock { position: absolute; top: 44px; left: 50%; transform: translateX(-50%); font-size: 28px; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ach { display: flex; gap: 10px; align-items: center; background: rgba(255, 255, 255, 0.05); border-radius: 14px; padding: 10px; box-shadow: inset 0 0 0 1px var(--line); }
.ach .ic { font-size: 30px; width: 40px; text-align: center; }
.ach b { display: block; font-size: 15px; }
.ach small { color: var(--muted); font-size: 12px; }
.ach.locked { opacity: 0.45; }
.ach.locked .ic { filter: grayscale(1); }
.stats-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.stat { background: rgba(255, 255, 255, 0.05); border-radius: 14px; padding: 10px 12px; box-shadow: inset 0 0 0 1px var(--line); }
.stat small { color: var(--muted); font-weight: 700; font-size: 12px; display: block; }
.stat b { font-family: var(--head); font-size: 24px; color: var(--gold2); }
.stat-table { grid-column: 1 / -1; width: 100%; border-collapse: collapse; font-size: 14px; }
.stat-table td, .stat-table th { padding: 4px 8px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.stat-table th { color: var(--gold2); font-size: 12px; text-transform: uppercase; }
.rules-body { columns: 2 320px; column-gap: 24px; }
.rule { break-inside: avoid; margin: 0 0 14px; }
.rule h3 { display: flex; gap: 8px; align-items: center; }
.rule p { margin: 0; color: #e2d8e6; font-size: 15px; line-height: 1.4; }
.set-list { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.set-list .toggle { margin: 6px 0; }
.set-list .choice { margin: 4px 0 8px; }
.lang-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.lang-list button { border: 0; border-radius: 12px; padding: 10px; cursor: pointer; background: rgba(255, 255, 255, 0.07); font-weight: 800; font-size: 16px; }
.lang-list button.on { background: var(--gold); color: #24160c; }
.bar { height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 10px 0; }
.bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .2s; }

.toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 70; background: var(--panel2); border: 2px solid var(--gold);
  border-radius: 999px; padding: 8px 20px; font-weight: 800; font-size: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: pop .2s ease; max-width: 92vw; text-align: center; }
.shake { animation: shake .3s ease; }
.rotate { display: none; }

/* ---------------------------------------------------------------- portrait / small screens */
@media (max-aspect-ratio: 1/1) {
  #table { flex-direction: column; justify-content: flex-start; gap: 6px; padding: 6px 8px; }
  #board-col { gap: 4px; }
  .pbar { height: 42px; }
  .avatar { width: 34px; height: 34px; }
  .clock { font-size: 20px; min-width: 74px; }
  #side { width: var(--bs); height: auto; flex: 1; min-height: 0; padding: 6px; gap: 5px; border-radius: 12px; overflow-y: auto; }
  #side-head { display: none; }
  .nav .nav-menu { display: block; }
  .nav button { padding: 4px 0; }
  .coach { font-size: 13px; padding: 5px 8px; }
  .coach-act { margin-top: 4px; }
  .pz-goal { font-size: 16px; }
  .court-portrait .bubble { bottom: -10px; top: auto; left: 4px; width: max-content; max-width: 180px; font-size: 13px; padding: 4px 10px; }
  .court-portrait .bubble::after { display: none; }
  .moves { grid-template-columns: none; display: flex; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; min-height: 34px; max-height: 38px; flex: none; }
  .moves .n { padding: 3px 2px 3px 6px; }
  .opening { display: none; }
  #review-box canvas { height: 56px; }
  .controls { grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .controls .btn { font-size: 18px; padding: 6px 2px; }
  .controls .btn .lbl-t { display: none; }
  .menu-grid { grid-template-columns: 1fr; gap: 14px; align-items: start; }
  .modes { grid-template-columns: 1fr 1fr; }
  .opp-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .opp img, .opp .ph { width: 52px; height: 52px; }
  .setup-row { grid-template-columns: 1fr; gap: 4px; }
  .pz-modes { grid-template-columns: 1fr 1fr; }
}
@media (max-aspect-ratio: 1/1) {
  .pbar { height: 46px; }
  .pinfo { line-height: 1.05; }
  .pname { font-size: 16px; }
  .caps { height: 13px; }
  .caps img { width: 13px; height: 13px; }
}
/* tall phones: there is room under the board, so the action buttons keep their words (older players) */
@media (max-aspect-ratio: 1/1) and (min-height: 700px) {
  .controls .btn { padding: 6px 2px 5px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
  .controls .btn .lbl-t { display: block; font-size: 11px; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 560px) {
  .modes { grid-template-columns: 1fr; }
  .mode { padding: 10px 12px; }
  .mode .mi { font-size: 30px; }
  .opp-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .opp b { font-size: 12px; }
  .opp small { display: none; }
  h2 { font-size: 24px; }
  .modal, .panel { padding: 14px; }
  .menu-row .btn { font-size: 14px; padding: 7px 10px; }
  .court-portrait, .court-portrait img { width: 80px; height: 80px; }
}
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .pbar { height: 40px; } .avatar { width: 32px; height: 32px; } .clock { font-size: 18px; min-width: 64px; }
  /* short landscape (phones, the portal's embedded frame): everything must fit without tiles overlapping */
  .overlay.menu { padding: 8px 10px; }
  .menu-grid { grid-template-columns: minmax(0, 1fr) minmax(0, clamp(230px, 34vw, 320px)); gap: 14px; align-items: start; padding: 2px; }
  .menu-main { gap: 8px; }
  .logo .l1 { font-size: clamp(28px, 7vh, 40px); }
  .logo .l2 { font-size: 14px; margin-top: 2px; }
  .chip { font-size: 13px; padding: 2px 10px; }
  .btn.big.continue { font-size: 16px; padding: 6px 14px; }
  .modes { gap: 8px; }
  .mode { padding: 6px 10px; grid-template-columns: 30px minmax(0, 1fr); column-gap: 8px; border-radius: 14px; min-height: 48px; }
  .mode .mi { font-size: 24px; }
  .mode b { font-size: 16px; }
  .mode small { font-size: 12px; line-height: 1.15; }
  .menu-row { gap: 6px; }
  .menu-row .btn { font-size: 13px; padding: 6px 10px; min-height: 36px; }
  .menu-side { gap: 8px; }
  .court-card { padding: 8px; gap: 8px; border-radius: 14px; }
  .court-portrait, .court-portrait img { width: 64px; height: 64px; }
  .court-portrait .bubble { bottom: -8px; top: auto; left: 0; font-size: 12px; padding: 3px 8px; max-width: 150px; }
  .court-portrait .bubble::after { display: none; }
  .court-info b { font-size: 18px; }
  .court-info span, .court-info small { font-size: 12px; }
  .quests-card { padding: 8px 12px; border-radius: 14px; }
  .quests-card h3 { font-size: 16px; margin-bottom: 2px; }
  .quest { margin: 4px 0; font-size: 13px; }
  .fact { display: none; }
}
@media (max-height: 420px) and (min-aspect-ratio: 1/1) {
  .logo .l2 { display: none; }
}
@media (max-height: 370px) and (min-aspect-ratio: 1/1) {
  .mode small { display: none; }
}
@media (max-width: 720px) and (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .mode small { display: none; }
  .menu-row .btn { padding: 6px 8px; }
}
/* phones & tablets: comfortable 44 px touch targets */
@media (pointer: coarse) {
  .menu-row .btn, .icon-btn, .nav button, .choice button, .lang-list button, .coach-act .btn, .controls .btn { min-height: 44px; }
  .icon-btn { min-width: 44px; }
  .toggle { min-height: 44px; }
  .court-portrait .bubble { font-size: 12px; }
}
@media (pointer: coarse) and (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .menu-row .btn { min-height: 40px; }
}
