/* Unequal · game UI. Restrained warm neutrals, tactile cards, single green action color. */
:root {
  color-scheme: dark;
  --bg: #262521;
  --header: #211f1c;
  --panel: #34322e;
  --panel-light: #3b3934;
  --panel-hover: #424039;
  --border: #504d46;
  --line: #4b4841;
  --text: #eeeae2;
  --muted: #b7b1a5;
  --faint: #908a7f;
  --green: #81aa59;
  --green-hover: #91b86b;
  --green-dark: #30412b;
  --red: #ba726d;
  --card: #e7e0d4;
  --card-ink: #302d27;
  --paper: #eee9df;
  --paper-low: #e2dbcd;
  --shadow: 0 2px 7px #0002;
  --radius: 8px;
  --body: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font: 14px/1.5 var(--body); }
button, input, select { font: inherit; }
button { cursor: pointer; transition: background .12s, border-color .12s, color .12s, transform .12s; }
button:disabled { opacity: .47; cursor: not-allowed; }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid #9bbc7b; outline-offset: 2px; }
a { color: inherit; }
h1,h2,h3,h4,p { margin: 0; }
h1 { font-size: clamp(23px, 2.5vw, 30px); font-weight: 750; letter-spacing: -.035em; line-height: 1.2; }
h2 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; line-height: 1.3; }
h3 { font-size: 15px; font-weight: 700; }
h4 { font-size: 14px; }
p { line-height: 1.55; }
.hidden { display: none !important; }
.muted,.caption { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.section-kicker, .panel-kicker, .eyebrow, .small-label { color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .035em; }
.line { height: 1px; background: var(--line); margin: 19px 0; }
.caption,.hint-text { font-size: 12px; }
.hint-text { color: var(--muted); margin: 12px 0 0; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 5px; padding: 4px 8px; font-size: 11px; font-weight: 650; color: var(--muted); background: #49463f; white-space: nowrap; }
.badge.success { color: #c4e0a6; background: #3d5233; }
.badge.gold { color: #e3d2a5; background: #544b35; }
.badge.coral { color: #efb8b0; background: #533734; }
.badge.neutral { color: var(--muted); background: #49463f; }
.text-action { border: 0; background: none; color: #c5daa9; padding: 4px; font-size: 12px; font-weight: 600; }
.text-action:hover { text-decoration: underline; }
label { display: block; margin: 0 0 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
input, select { width: 100%; min-height: 40px; border-radius: 6px; border: 1px solid #666055; color: var(--text); background: #262521; padding: 9px 11px; outline: 0; }
input::placeholder { color: #928c81; }
input[type=checkbox] { min-height: 0; width: 16px; height: 16px; accent-color: var(--green); }
select { padding-right: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 6px; border: 1px solid transparent; min-height: 40px; padding: 9px 16px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.btn-primary { background: var(--green); color: #1c2517; border-color: var(--green); }
.btn-primary:hover:not(:disabled) { background: var(--green-hover); }
.btn-secondary { background: #555249; border-color: #666258; color: #f6f3ed; }
.btn-secondary:hover:not(:disabled),.btn-subtle:hover:not(:disabled) { background: #625e55; }
.btn-subtle { color: var(--text); background: #46433d; border-color: #5d594f; }
.btn-small { min-height: 33px; font-size: 12px; padding: 6px 11px; }
.btn-wide { width: 100%; }
.btn-icon { width: 33px; padding: 0; min-width: 33px; font-size: 20px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 22px; }
.page-heading p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-heading h2 { margin: 6px 0; }
.section-heading p { margin-top: 4px; color: var(--muted); font-size: 13px; }
.grid-two { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.grid-three { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 18px; }

/* App navigation, analogous to a focused game client's lobby rather than a website dashboard. */
.app-header { height: 64px; background: var(--header); border-bottom: 1px solid #3a3832; }
.header-inner { max-width: 1310px; margin: auto; height: 100%; padding: 0 25px; display: flex; align-items: center; gap: 30px; }
.header-brand { background: none; border: 0; color: var(--text); padding: 0; display: inline-flex; align-items: center; gap: 9px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 37px; height: 37px; display: grid; place-items: center; background: var(--green); color: #24301d; border-radius: 6px; font: 800 26px/1 var(--body); }
.brand-name { font-size: 23px; line-height: 1; font-weight: 820; letter-spacing: -.07em; }
.brand-period { color: var(--green); }
.main-nav { display: flex; align-items: stretch; height: 100%; gap: 2px; }
.nav-item { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; color: #b2aea6; padding: 0 15px; font-size: 13px; font-weight: 650; position: relative; }
.nav-item:hover { color: var(--text); background: #302e29; }
.nav-item.active { color: var(--text); }
.nav-item.active::after { content: ''; position: absolute; bottom: 0; height: 3px; left: 14px; right: 14px; border-radius: 3px 3px 0 0; background: var(--green); }
.live-dot,.turn-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #bbac7a; }
.header-right { display: flex; align-items: center; gap: 13px; margin-left: auto; }
.connection { display: inline-flex; align-items: center; gap: 6px; color: var(--faint); font-size: 11px; white-space: nowrap; }
.connection i { width: 7px; height: 7px; border-radius: 50%; background: #928c81; }
.connection.online i { background: var(--green); }
.connection.offline i { background: #bd7c72; }
.user-chip { border: 0; color: var(--text); background: none; display: flex; align-items: center; gap: 9px; padding: 2px 4px; font-size: 12px; font-weight: 700; }
.user-chip small { display: block; font-size: 10px; color: var(--muted); font-weight: 500; text-align: left; }
.user-avatar,.profile-avatar,.player-avatar { width: 34px; height: 34px; border-radius: 5px; display: grid; place-items: center; color: #efe9dd; background: #635d4e; font-size: 16px; font-weight: 750; flex-shrink: 0; }
.logout-header { background: none; color: var(--muted); border: 0; font-size: 22px; padding: 4px; }
.logout-header:hover { color: var(--text); }
.main-content { max-width: 1250px; margin: 0 auto; padding: 30px 24px 85px; min-height: calc(100vh - 64px); }
.mobile-nav { display: none; }

/* Authentication */
.auth-layout { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(ellipse at center, #34352e 0%, #262521 65%); }
.auth-card { width: min(100%,420px); background: var(--panel); border-radius: 10px; border: 1px solid #5b554a; padding: 33px; box-shadow: 0 20px 80px #0004; }
.brand-center { justify-content: center; }
.auth-equation { margin: 26px 0 26px; padding: 17px 18px; display: flex; gap: 30px; justify-content: center; align-items: center; font: 30px Georgia, 'Times New Roman', serif; background: #e3ddce; color: #3a372f; border-radius: 6px; }
.auth-eq-symbol { color: #808071; font-size: 23px; }
.auth-card h1 { text-align: center; font-size: 23px; }
.auth-card > p { text-align: center; }
.auth-card > p.muted { font-size: 13px; margin: 7px 0 20px; }
.auth-switch { display: grid; grid-template-columns: 1fr 1fr; background: #272520; padding: 4px; border-radius: 7px; margin-bottom: 24px; }
.auth-switch button { border: 0; color: var(--muted); background: none; border-radius: 5px; padding: 10px; font-size: 13px; font-weight: 700; }
.auth-switch button.active { background: #4c493f; color: var(--text); }
.auth-card form label { margin-top: 15px; }
.auth-card form input { background: #292823; }
.auth-card form .btn { margin-top: 22px; }
.auth-foot { margin: 24px 0 0; font-size: 11px; color: var(--faint); }

/* Mode chooser + lobby */
.lobby-layout { display: grid; grid-template-columns: minmax(0,1.8fr) minmax(270px,.88fr); align-items: start; gap: 17px; }
.mode-panel .section-kicker { margin-bottom: 12px; }
.mode-group { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; }
.mode-btn { min-height: 67px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 2px; background: #2b2a25; border: 1px solid #625d52; border-radius: 6px; color: var(--muted); }
.mode-btn:hover:not(.active) { background: #3c3a33; color: var(--text); }
.mode-btn.active { color: #e5f0db; border: 2px solid var(--green); background: var(--green-dark); }
.mode-symbol { font-size: 24px; font-family: Georgia,serif; line-height: 1.25; }
.mode-name { font-size: 11px; font-weight: 600; }
.mode-hint { color: var(--muted); font-size: 12px; margin: 12px 1px 0; }
.play-choice { display: flex; align-items: center; gap: 15px; padding: 20px 2px; border-bottom: 1px solid var(--line); }
.play-choice:last-child { padding-bottom: 2px; border-bottom: 0; }
.choice-symbol { display: grid; place-items: center; color: #d6d0c2; background: #4b493f; border-radius: 6px; width: 44px; height: 44px; flex-shrink: 0; font-size: 24px; }
.primary-choice .choice-symbol { color: #d5eac0; background: #43583b; }
.choice-copy { flex: 1; min-width: 0; }
.choice-copy h2 { font-size: 15px; }
.choice-copy p { color: var(--muted); font-size: 12px; margin-top: 3px; }
.choice-controls { display: flex; gap: 7px; align-items: center; }
.choice-controls select { width: 110px; }
.choice-controls input { width: 145px; }
.queue-status { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding: 12px 14px; border-radius: 6px; background: #434b39; color: #daebcd; font-size: 12px; margin-top: 8px; }
.profile-mini-top { display: flex; gap: 11px; align-items: center; }
.small-avatar { width: 44px; height: 44px; font-size: 20px; }
.profile-mini-top strong { display: block; }
.profile-mini-top span { display: block; color: var(--muted); font-size: 12px; }
.mini-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; margin: 21px 0 17px; }
.mini-stats > div { display: flex; flex-direction: column; gap: 2px; }
.mini-stats strong { font-size: 21px; }
.mini-stats span { font-size: 11px; color: var(--muted); }
.xp-progress,.deck-progress { height: 7px; background: #24231e; border-radius: 12px; overflow: hidden; margin-bottom: 7px; }
.xp-progress > div,.deck-progress > div { height: 100%; background: var(--green); border-radius: 12px; }
.invitation-row,.recent-row,.history-row { border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; }
.invitation-row:first-child,.recent-row:first-child { border-top: 0; }
.recent-row { font-size: 12px; }
.empty-state { color: var(--muted); font-size: 12px; padding: 15px 2px; }

/* Cards are physical looking playing pieces, not dashboard widgets. */
.game-card { min-width: 0; width: 100%; min-height: 151px; display: flex; flex-direction: column; justify-content: space-between; padding: 11px; border-radius: 7px; border: 2px solid #b9b2a5; background: var(--card); color: var(--card-ink); box-shadow: 0 2px 0 #867d6e,0 4px 7px #0002; text-align: left; position: relative; overflow: hidden; }
.game-card::before { content: ''; position: absolute; left: 7px; right: 7px; top: 7px; bottom: 7px; border: 1px solid #d0c7b8; border-radius: 3px; pointer-events: none; }
.game-card.playable:hover { transform: translateY(-3px); border-color: #8d996a; box-shadow: 0 5px 0 #7f786a,0 7px 10px #0003; }
.game-card.selected { background: #f0e8d6; border-color: #80a35c; box-shadow: 0 0 0 3px #799b57,0 6px 12px #0004; transform: translateY(-4px); }
.game-card.selected::after { content: '✓'; position: absolute; top: 7px; right: 8px; color: #396331; font-weight: 800; font-size: 15px; }
.game-card.locked { opacity: .43; filter: grayscale(.65); }
.game-card.op-function { background: #d9ded1; }
.game-card.op-function.selected { background: #e6eadc; }
.card-meta,.card-foot { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 3px; font-size: 10px; color: #6b665b; font-weight: 650; }
.card-index { color: #8c8679; white-space: nowrap; }
.card-math { position: relative; text-align: center; display: grid; place-items: center; min-height: 58px; font-size: 25px; font-family: Georgia,serif; color: #302e28; overflow: auto hidden; }
.card-math mjx-container { margin: 0!important; }
.card-count { font-size: 12px; color: #444034; }

/* Deck builder */
.deck-layout { display: grid; grid-template-columns: minmax(0,1.65fr) minmax(290px,.85fr); gap: 17px; align-items: start; }
.deck-library .mode-group { max-width: 570px; }
.deck-library .hint-text { margin: 17px 0; }
.collection-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 11px; }
.collection-grid .game-card { min-height: 145px; }
.deck-sidebar { position: sticky; top: 18px; }
.deck-sidebar h2 { margin: 9px 0; }
.deck-count { font-size: 25px; font-weight: 750; }
.deck-count span { font-size: 15px; color: var(--muted); font-weight: 500; }
.deck-sidebar .deck-progress { margin: 10px 0 6px; }
.deck-picked { max-height: 430px; overflow-y: auto; margin: 14px 0; padding-right: 2px; }
.deck-row { display: flex; align-items: center; gap: 9px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.deck-row-math { flex: 0 0 75px; white-space: nowrap; text-align: center; font-size: 17px; }
.deck-row-math mjx-container { margin: 0!important; }
.deck-row-meta { flex: 1; font-size: 12px; color: var(--muted); }
.deck-row-qty { font-size: 13px; font-weight: 700; }

/* Match: chess-like hierarchy. Opponent top, board center, player/hand bottom. */
.game-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 19px; }
.game-overline { color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 5px; }
.game-overline span { margin: 0 6px; }
.game-heading-right { display: flex; align-items: center; gap: 10px; }
.game-layout { display: grid; grid-template-columns: minmax(0,1fr) 320px; gap: 19px; align-items: start; }
.game-primary,.game-sidebar { min-width: 0; }
.game-sidebar { display: flex; flex-direction: column; gap: 15px; }
.player-strip { display: flex; align-items: center; gap: 10px; padding: 10px 4px; }
.player-avatar { width: 37px; height: 37px; }
.opponent-avatar { background: #795a52; }
.own-avatar { background: #5b7652; }
.player-label { flex: 1; min-width: 0; }
.player-label strong { display: block; font-weight: 750; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-label span { display: block; font-size: 11px; color: var(--muted); }
.player-counter { display: flex; flex-direction: column; align-items: end; }
.player-counter strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.player-counter strong span { font-size: 12px; font-weight: 500; color: var(--muted); }
.player-counter>span { font-size: 10px; color: var(--muted); }
.math-board { border-radius: 7px; overflow: hidden; background: #a9a394; border: 7px solid #686253; box-shadow: 0 3px 0 #504c41,0 9px 17px #0003; }
.math-lane { background: var(--paper); min-width: 0; padding: 13px 20px 16px; border-left: 5px solid #77766b; }
.opponent-lane { background: #e7dfd4; border-left-color: #a36a60; }
.own-lane { background: #ede9dc; border-left-color: #718e5d; }
.lane-heading { display: flex; justify-content: space-between; align-items: center; color: #686257; font-size: 11px; font-weight: 750; }
.lane-side-dot { width: 8px; height: 8px; border-radius: 50%; }
.opponent-dot { background: #a36a60; }
.own-dot { background: #718e5d; }
.formula-wrap { color: #2d2a25; font-size: clamp(20px,2.7vw,29px); text-align: center; display: flex; justify-content: safe center; align-items: center; padding: 16px 6px; min-height: 104px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.formula-wrap mjx-container { margin: 0!important; max-width: none; flex-shrink: 0; }
.math-result { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: #5f594d; border-top: 1px solid #d0c7b7; padding-top: 12px; font-size: 11px; }
.math-result strong { color: #26241f; font-size: 22px; font-weight: 700; overflow-x: auto; white-space: nowrap; max-width: 80%; font-family: Georgia,serif; }
.math-result mjx-container { margin: 0!important; }
.math-divider { background: #b8af9e; color: #494438; height: 40px; display: flex; justify-content: center; align-items: center; gap: 10px; font: 24px Georgia,serif; }
.math-divider small { font: 600 11px var(--body); color: #6b6254; }
.math-legend { padding: 8px 12px 2px; background: #686253; color: #f4eee5; display: flex; justify-content: space-between; gap: 14px; font-size: 10px; flex-wrap: wrap; }
.enemy-mark { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: #be7b72; margin-right: 5px; }
.hand-section { margin-top: 15px; }
.hand-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.hand-head h2 { font-size: 16px; }
.hand-head p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hand-remaining { font-size: 11px; color: var(--muted); border: 1px solid var(--border); background: #383630; padding: 5px 8px; border-radius: 5px; white-space: nowrap; }
.hand-grid { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 10px; padding: 5px 4px 9px; }
.hand-grid .game-card { min-height: 156px; }
.turn-panel { padding: 18px; }
.turn-head { display: flex; gap: 10px; align-items: center; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.turn-dot.active { background: var(--green); }
.turn-head strong { font-size: 15px; display: block; }
.turn-head span:not(.turn-dot) { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; }
.move-card-preview { padding: 18px 0 10px; }
.move-preview-math { margin-top: 10px; height: 65px; display: flex; align-items: center; justify-content: center; background: #e7e0d4; color: #2f2d26; border-radius: 5px; font: 26px Georgia,serif; }
.move-preview-math mjx-container { margin: 0!important; }
.preview-placeholder { font: 12px var(--body); color: #756f62; }
.action-kicker { margin: 12px 0 9px; }
.action-targets { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 7px; }
.target-btn { min-height: 76px; border-radius: 6px; background: #292822; border: 1px solid #696356; color: #d6d0c6; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 650; text-align: center; padding: 6px 3px; }
.target-btn:hover:not(.active) { background: #4a473e; }
.target-btn.active { background: #45583a; color: #e7f1dc; border: 2px solid var(--green); }
.target-btn.enemy.active { border-color: #bd847a; background: #684741; color: #f2e2dc; }
.target-btn.discard.active { border-color: #aaa18d; background: #555147; }
.target-symbol { font-size: 22px; font-weight: 400; line-height: 1; }
.play-submit { margin-top: 14px; min-height: 48px; justify-content: space-between; font-size: 14px; }
.action-help { color: var(--muted); font-size: 12px; margin-top: 12px; }
.action-help strong { color: var(--text); }
.end-panel { margin-top: 17px; }
.end-panel p { margin-bottom: 15px; color: var(--muted); }
.history-panel .timeline { max-height: 274px; overflow: auto; }
.timeline-item { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.timeline-item:first-child { border-top: 0; }
.timeline-num { width: 20px; color: var(--faint); font-size: 11px; }
.timeline-copy { flex: 1; font-size: 12px; color: #d6d0c6; overflow-wrap: anywhere; }
.rules-panel { padding: 0; }
.rules-panel summary { padding: 13px 18px; font-weight: 600; font-size: 12px; cursor: pointer; }
.rules-panel p { font-size: 12px; color: var(--muted); padding: 0 18px 17px; }

/* Profile and admin */
.profile-hero { display: flex; align-items: center; gap: 16px; }
.profile-avatar { width: 76px; height: 76px; font-size: 34px; border-radius: 8px; }
.profile-stats { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.profile-stat { background: var(--panel); border: 1px solid var(--border); padding: 20px; border-radius: 8px; }
.stat-number { font-size: 26px; font-weight: 800; }
.stat-label { color: var(--muted); font-size: 11px; }
.ink-cyan { color: #aad38d; }
.ink-coral { color: #d89b8e; }
.ink-amber { color: #ddc38c; }
.history-title { font-weight: 700; font-size: 13px; }
.history-sub { color: var(--muted); font-size: 11px; margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.form-field { min-width: 0; }
.admin-table { display: flex; flex-direction: column; }
.admin-row { padding: 11px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 92px minmax(0,1fr) 85px 80px 74px; align-items: center; gap: 11px; }
.admin-row:first-child { border-top: 0; }
.admin-math { font-size: 18px; }
.admin-math mjx-container { margin: 0!important; }
.admin-kind { color: var(--muted); font-size: 12px; }
.admin-row input[type=number] { min-height: 34px; padding: 6px; }
.admin-row .toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 0; }
.toast { position: fixed; right: 18px; bottom: 22px; z-index: 1000; padding: 13px 17px; max-width: min(400px,calc(100vw - 36px)); font-size: 13px; color: #eef5e7; background: #3f5738; border: 1px solid #67865b; border-radius: 7px; box-shadow: 0 8px 28px #0004; }
.toast.error { color: #fff0ed; background: #653e3a; border-color: #9c6761; }

@media(max-width:1050px) {
  .game-layout { grid-template-columns: minmax(0,1fr) 286px; gap: 13px; }
  .lobby-layout { grid-template-columns: minmax(0,1.5fr) minmax(250px,.85fr); }
  .choice-controls { flex-wrap: wrap; justify-content: end; }
  .collection-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media(max-width:830px) {
  .main-content { padding: 22px 17px 90px; }
  .header-inner { padding: 0 16px; gap: 20px; }
  .main-nav { gap: 0; }
  .nav-item { padding: 0 9px; }
  .game-layout, .lobby-layout, .deck-layout { grid-template-columns: minmax(0,1fr); }
  .game-sidebar { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .game-sidebar .rules-panel { grid-column: 1/-1; }
  .deck-sidebar { position: static; }
  .deck-picked { max-height: 280px; }
  .collection-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
}
@media(max-width:620px) {
  .app-header { height: 56px; }
  .header-inner { padding: 0 15px; }
  .brand-mark { width: 32px; height: 32px; font-size: 22px; }
  .brand-name { font-size: 21px; }
  .main-nav,.connection,.logout-header,.user-chip .user-name { display: none; }
  .main-content { padding: 19px 12px 115px; min-height: calc(100vh - 56px); }
  .mobile-nav { display: flex; justify-content: space-around; align-items: center; position: fixed; bottom: 0; left: 0; right: 0; z-index: 90; background: #211f1cf5; border-top: 1px solid #454137; padding: 7px 4px max(8px,env(safe-area-inset-bottom)); box-shadow: 0 -7px 30px #0004; }
  .mobile-nav button { border: 0; border-radius: 5px; padding: 5px 8px; background: none; color: #b1aa9e; font: 600 10px var(--body); min-width: 51px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .mobile-nav button span { font-size: 22px; font-weight: 500; line-height: 1.1; }
  .mobile-nav button.active { color: #d2ebbf; background: #35472e; }
  .panel { padding: 16px; }
  .page-heading { margin-bottom: 17px; }
  .page-heading .btn { font-size: 12px; }
  .play-choice { flex-wrap: wrap; align-items: center; gap: 10px; }
  .play-choice .choice-copy { min-width: calc(100% - 65px); }
  .play-choice > .btn,.choice-controls { margin-left: 54px; }
  .choice-controls { flex: 1; justify-content: start; }
  .choice-controls select,.choice-controls input { flex: 1; min-width: 95px; width: auto; }
  .game-heading { align-items: start; }
  .game-heading-right .btn { display: none; }
  .game-sidebar { display: flex; flex-direction: column; }
  .math-board { border-width: 5px; }
  .math-lane { padding: 10px 13px 12px; border-left-width: 4px; }
  .formula-wrap { font-size: 22px; min-height: 92px; padding: 13px 4px; }
  .math-result strong { font-size: 20px; }
  .hand-grid { gap: 6px; padding: 5px 2px 9px; }
  .hand-grid .game-card { padding: 7px 5px; min-height: 125px; }
  .hand-grid .game-card::before { inset: 4px; }
  .hand-grid .card-meta,.hand-grid .card-foot { font-size: 8px; }
  .hand-grid .card-index { display: none; }
  .hand-grid .card-math { font-size: clamp(15px,4.9vw,24px); min-height: 55px; }
  .hand-grid .card-foot { text-align: center; justify-content: center; }
  .turn-panel { padding: 16px; }
  .target-btn { min-height: 60px; }
  .collection-grid { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
  .collection-grid .game-card { min-height: 130px; padding: 8px; }
  .collection-grid .card-math { font-size: 21px; }
  .grid-two,.grid-three { grid-template-columns: minmax(0,1fr); }
  .admin-row { display: flex; flex-wrap: wrap; gap: 8px; }
  .admin-row .admin-kind { flex: 1; }
  .admin-row .form-field { width: 70px; }
  .toast { bottom: 90px; }
}
@media(max-width:375px) {
  .hand-grid { gap: 4px; }
  .hand-grid .game-card { padding: 6px 3px; }
  .hand-grid .card-meta,.hand-grid .card-foot { font-size: 7px; }
  .mode-btn { min-height: 60px; }
  .mode-name { font-size: 10px; }
  .collection-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .page-heading .btn { display: none; }
}
@media(prefers-reduced-motion:reduce) {
  *,*::before,*::after { transition: none!important; animation: none!important; scroll-behavior: auto!important; }
}

/* Drag a card onto either equation, or the reachable drop dock on phones. */
.hand-grid .game-card.playable { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.hand-grid .game-card.playable:active { cursor: grabbing; }
.card-drag-ghost {
  position: fixed; z-index: 150; pointer-events: none; margin: 0;
  transform: translate(-50%, -60%) rotate(-3deg);
  box-shadow: 0 12px 32px #0006; opacity: .95; min-height: 118px;
  cursor: grabbing;
}
.drag-active .math-lane { outline: 2px dashed #8a8578; outline-offset: -5px; transition: background .12s, outline-color .12s; }
.drag-active .math-lane.own-lane { outline-color: #7a9d64; }
.drag-active .math-lane.opponent-lane { outline-color: #bc8075; }
.math-lane { position: relative; }
.lane-drop-label { display: none; font-size: 11px; font-weight: 700; letter-spacing: .01em; color: #655f53; margin: -2px 0 6px; text-align: center; pointer-events: none; }
.drag-active .lane-drop-label { display: block; }
.math-lane.drop-hover, .math-lane.own-lane.drop-hover { background: #dce9d1; outline: 4px solid #799d64; outline-offset: -5px; }
.math-lane.opponent-lane.drop-hover { background: #eed8d2; outline-color: #b87970; }
.target-btn.drop-hover { outline: 3px solid #d7c7a1; outline-offset: 2px; }
.drag-dock {
  display: none; position: fixed; z-index: 130; bottom: 22px; left: 50%;
  transform: translateX(-50%); width: min(500px, calc(100vw - 24px));
  padding: 8px; gap: 8px; border-radius: 12px; border: 1px solid #605b51;
  background: #2c2b27f5; box-shadow: 0 10px 38px #0008;
}
.drag-active .drag-dock { display: flex; }
.dock-zone { flex: 1; min-height: 66px; padding: 10px 5px; border: 1px dashed #8f8b80; border-radius: 7px; display: flex; align-items: center; justify-content: center; text-align: center; color: #e8e3d9; font-size: 12px; font-weight: 700; }
.dock-zone.own { border-color: #86a775; }
.dock-zone.foe { border-color: #b98278; }
.dock-zone.discard { border-color: #b3aa9b; }
.dock-zone.own.drop-hover { background: #536b45; border-style: solid; }
.dock-zone.foe.drop-hover { background: #83554d; border-style: solid; }
.dock-zone.discard.drop-hover { background: #645f53; border-style: solid; }
@media (max-width:620px) {
  .drag-dock { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
  .dock-zone { min-height: 58px; font-size: 11px; }
  .card-drag-ghost { min-height: 126px; }
}
/* Progress is visible throughout the app, including on small screens. */
.progress-banner { max-width:1440px; margin:20px auto 0; padding:0 28px; display:flex; align-items:center; gap:18px; }
.level-medallion { flex:0 0 88px; padding:9px; border:1px solid #9ac471; border-radius:12px; background:var(--green-dark); color:#d5edbb; }
.level-medallion small { display:block; letter-spacing:.12em; font-size:10px; }
.level-medallion strong { display:block; font-size:32px; line-height:1.1; }
.progress-copy { flex:1; min-width:0; }
.progress-copy .xp-progress { margin:7px 0; height:9px; }
.progress-copy .row { flex-wrap:wrap; gap:2px 12px; }
.tutorial-entry { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:20px; }
.tutorial-entry p { color:var(--muted); margin-top:4px; }
.tutorial-guide { border:2px solid var(--green); background:#303b29; margin-bottom:22px; }
.tutorial-guide h2 { font-size:24px; margin:8px 0; }
.tutorial-guide p { max-width:900px; font-size:16px; margin-bottom:12px; }
.tutorial-guide .btn { margin:8px 8px 0 0; }
.collection-level { margin-top:24px; padding-top:16px; border-top:1px solid var(--line); }
.collection-level .collection-grid { margin-top:12px; }
.deck-sidebar .btn-wide { margin-top:10px; }
@media(max-width:600px) {
 .progress-banner { padding:0 16px; gap:12px; margin-top:14px; }
 .level-medallion { flex-basis:64px; }
 .level-medallion strong { font-size:26px; }
 .progress-copy .row { font-size:12px; }
 .progress-copy .caption { font-size:10px; }
 .tutorial-entry { align-items:flex-start; flex-direction:column; }
 .tutorial-guide h2 { font-size:20px; }
}

/* Celebration system */
.sound-toggle { width:34px; height:34px; flex-shrink:0; border:1px solid var(--border); border-radius:50%; color:var(--muted); background:transparent; font-size:20px; }
.sound-toggle[aria-pressed=true] { color:#c5ed9c; border-color:var(--green); background:var(--green-dark); }
.progress-banner { position:relative; }
.xp-float { position:absolute; right:32px; top:4px; z-index:50; padding:7px 14px; border-radius:20px; background:#dcf4af; color:#25391a; font-size:20px; font-weight:850; box-shadow:0 4px 20px #0005; pointer-events:none; animation:xp-rise 2.1s ease-out both; }
.reward-dialog { width:min(510px,calc(100vw - 28px)); max-height:calc(100dvh - 32px); padding:38px 32px 28px; overflow-x:hidden; border:1px solid #8da76b; border-radius:24px; color:var(--text); background:radial-gradient(ellipse at top,#394a2f, #292b25 65%); text-align:center; box-shadow:0 24px 100px #0009; }
.reward-dialog[open] { animation:reward-arrive .48s cubic-bezier(.18,1.4,.45,1) both; }
.reward-dialog::backdrop { background:#12150fba; backdrop-filter:blur(6px); }
.reward-dialog[data-kind=loss] { background:radial-gradient(ellipse at top,#364045,#292b2b 65%); border-color:#7b949e; }
.reward-dialog[data-kind=draw] { background:radial-gradient(ellipse at top,#49432d,#2b2a25 65%); border-color:#c4aa68; }
.reward-close { position:absolute; right:14px; top:12px; width:34px; height:34px; border:0; background:#ffffff0c; border-radius:50%; color:var(--muted); font-size:24px; z-index:3; }
.reward-icon { display:grid; place-items:center; position:relative; width:110px; height:110px; margin:6px auto 24px; border-radius:30%; background:linear-gradient(145deg,#f7e3a2,#d4a84b); color:#5e4411; font-size:68px; line-height:1; box-shadow:0 8px 0 #896d2e,0 16px 38px #edca6930,inset 0 2px 0 #fff7; transform:rotate(-7deg); animation:medal-pop .8s cubic-bezier(.2,1.6,.5,1) both; }
.reward-dialog[data-kind=level] .reward-icon { background:linear-gradient(145deg,#dcf9bd,#8abd5f); color:#385c22; box-shadow:0 8px 0 #527d31,0 16px 38px #9bdb6830; }
.reward-dialog[data-kind=loss] .reward-icon { background:#a2bbc6; color:#354950; box-shadow:0 8px 0 #536b76; }
.reward-eyebrow { color:#d9c991; font-size:11px; font-weight:800; letter-spacing:.16em; margin-bottom:10px; }
.reward-dialog h2 { font-size:clamp(28px,6vw,38px); letter-spacing:-.045em; margin-bottom:12px; }
#reward-copy { color:#c7cbbd; line-height:1.65; margin:0 auto 18px; max-width:390px; }
.reward-xp { display:flex; justify-content:center; align-items:baseline; gap:7px; color:#c4ee9c; font-size:28px; font-weight:800; margin:16px 0; }
.reward-xp strong { font-size:48px; font-variant-numeric:tabular-nums; }
.reward-xp span { font-size:15px; }
.reward-score { display:grid; grid-template-columns:1fr 1fr; border:1px solid #ffffff1c; border-radius:12px; margin:18px 0 24px; background:#0002; }
.reward-score > span { padding:12px; min-width:0; color:var(--muted); overflow:auto; font-size:12px; }
.reward-score > span + span { border-left:1px solid #ffffff1c; }
.reward-score b { display:block; color:var(--text); font-size:20px; margin-top:5px; }
.reward-level-path { display:flex; align-items:center; justify-content:center; gap:24px; margin:16px 0 24px; font-size:30px; }
.reward-level-path > span:first-child { color:var(--muted); }
.reward-level-path strong { display:grid; place-items:center; min-width:80px; height:80px; border:2px solid var(--green); border-radius:20px; font-size:42px; color:#c4ee9c; background:#86b95715; }
.reward-arrow { color:var(--green); }
.unlock-list { display:flex; flex-wrap:wrap; gap:8px; justify-content:center; margin:16px 0; }
.unlock-list span { padding:7px 10px; color:#d6eac1; background:#ffffff08; border:1px solid #b9e18d30; border-radius:8px; font-size:12px; animation:unlock-arrive .45s ease-out both; }
.unlock-list span:nth-child(2n) { animation-delay:.1s; }
.reward-caption { color:var(--muted); font-size:12px; margin:18px 0 22px; }
.reward-dialog .btn-primary { box-shadow:0 4px 0 #4c6b31; min-height:48px; font-size:15px; }
.confetti-layer { position:absolute; inset:0; overflow:hidden; pointer-events:none; border-radius:24px; z-index:2; }
.confetti-layer i { position:absolute; left:var(--x); top:-20px; width:8px; height:14px; border-radius:2px; background:var(--color); animation:confetti-fall 2.8s var(--delay) ease-in both; }
.reward-impact { animation:impact-pop .55s ease-out; }
.reward-your-turn { animation:turn-glow .6s ease-out; }
.game-card.selected { box-shadow:0 0 0 3px var(--green),0 9px 24px #0003; }
.game-card.playable:hover { transform:translateY(-5px); }
.game-card { transition:transform .16s ease,box-shadow .16s ease,border-color .16s ease; }
.achievement-panel { margin-bottom:20px; }
.achievement-top { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:16px; }
.streak-chip { color:#f2cd79; background:#dca74514; border:1px solid #dca74544; padding:8px 12px; border-radius:10px; white-space:nowrap; }
.achievement-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:10px; }
.achievement { padding:14px 10px; border:1px solid var(--line); border-radius:12px; background:#ffffff03; }
.achievement.earned { border-color:#88b65f88; background:#83b55512; }
.achievement-icon { font-size:24px; color:var(--faint); margin-bottom:5px; }
.achievement.earned .achievement-icon { color:#e4ca83; }
.achievement strong { display:block; font-size:13px; }
.achievement small { display:block; font-size:11px; color:var(--muted); margin-top:5px; }
.milestone-track { height:5px; background:#0003; border-radius:10px; margin-top:10px; overflow:hidden; }
.milestone-track i { display:block; height:100%; background:var(--green); transition:width .6s ease; }
@keyframes reward-arrive { from { opacity:0; transform:translateY(28px) scale(.88); } to { opacity:1; transform:none; } }
@keyframes medal-pop { from { opacity:0; transform:rotate(-22deg) scale(.5); } to { opacity:1; transform:rotate(-7deg) scale(1); } }
@keyframes unlock-arrive { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:none; } }
@keyframes confetti-fall { to { transform:translate(var(--drift),650px) rotate(var(--spin)); opacity:0; } }
@keyframes xp-rise { 0% { opacity:0; transform:translateY(18px) scale(.8); } 15%,65% { opacity:1; transform:translateY(0) scale(1); } 100% { opacity:0; transform:translateY(-24px); } }
@keyframes impact-pop { 30% { box-shadow:0 0 0 4px #a6d87588,0 0 28px #9ac66e33; transform:scale(1.012); } }
@keyframes turn-glow { 40% { box-shadow:0 0 0 3px #a6d87599; } }
@media(max-width:600px) { .reward-dialog { padding:28px 20px 22px; } .reward-icon { width:85px; height:85px; font-size:52px; margin-bottom:20px; } .achievement-grid { grid-template-columns:repeat(2,1fr); } .achievement-top { align-items:flex-start; } .streak-chip { font-size:11px; } }
@media(prefers-reduced-motion:reduce) { *,*::before,*::after { animation:none!important; transition:none!important; scroll-behavior:auto!important; } .confetti-layer { display:none; } .game-card.playable:hover { transform:none; } }

/* Keep turn, values and move targets within reach on phones. */
.sticky-turn { position:sticky; top:0; z-index:100; padding:12px 16px; background:#51483b; border:2px solid #b5a17b; border-radius:8px; margin-bottom:12px; font-weight:750; }
.sticky-turn.your-turn { background:#344d29; border-color:#a3ca77; color:#e5ffd1; }
.quick-actions { position:sticky; bottom:12px; z-index:130; display:flex; gap:8px; padding:10px; background:#282720fa; border:1px solid #827a69; border-radius:12px; box-shadow:0 4px 24px #0008; margin-top:14px; }
.quick-actions .dock-zone { flex-direction:column; background:#383a30; cursor:pointer; }
.quick-actions small { display:block; font-size:11px; font-weight:400; }
.quick-actions button:disabled { opacity:.5; cursor:not-allowed; }
.hand-grid .illegal-card { background:#f0ceca; border-color:#b75049; }
.legality-note { position:relative; color:#8b2621; font-size:10px; text-align:center; }
.math-result strong { overflow:visible; white-space:normal; overflow-wrap:anywhere; font-family:var(--body); }
.math-result { gap:12px; }
.friend-room { margin-bottom:20px; }
.friend-room select { width:auto; margin-left:12px; }
.game-primary { min-width:0; }
@media(max-width:620px) {
 .quick-actions { position:fixed; left:8px; right:8px; bottom:calc(66px + env(safe-area-inset-bottom,0px)); margin:0; }
 .quick-actions .dock-zone { min-height:60px; padding:6px 3px; }
 .game-layout { padding-bottom:110px; }
 .formula-wrap { min-height:48px; padding:8px 2px; font-size:18px; }
 .math-lane { padding:8px; }
 .math-board { border-width:3px; }
 .player-strip { padding:7px; }
 .math-legend { display:none; }
 .hand-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
 .hand-grid .game-card { min-height:118px; }
 .hand-grid .game-card.playable { touch-action:pan-y; }
 .sticky-turn { font-size:12px; padding:9px; }
 .hand-section { margin-top:8px; }
 .game-sidebar .turn-panel:has(.end-panel) { display:block; }
 .game-sidebar .turn-panel:not(:has(.end-panel)) { display:none; }
}
