:root {
  color-scheme: dark;
  --bg: #07111d;
  --panel: #101b2a;
  --line: #26384d;
  --line-bright: #3d5873;
  --text: #f6f8fb;
  --muted: #a7b7cc;
  --blue: #2b8cff;
  --blue-light: #86d4ff;
  --red: #e43832;
  --danger: #ff8c81;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: radial-gradient(ellipse at 20% 0, #102b47 0, transparent 45rem), #050c14;
}

button, select, input { font: inherit; }
button, select { min-height: 44px; }
button { touch-action: manipulation; cursor: pointer; }
button:disabled, select:disabled { cursor: not-allowed; opacity: 0.5; }
:focus-visible { outline: 3px solid #ffdb76; outline-offset: 4px; }
h1, h2, p { margin: 0; }

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: #0309106e;
  border-inline: 1px solid #ffffff0d;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.3rem clamp(0.75rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 0.8rem; }
.brand-mark { color: var(--blue); font-size: 4rem; line-height: 1; filter: drop-shadow(0 0 14px #2b8cff55); }
h1 { font-size: clamp(1.5rem, 3.6vw, 3.25rem); font-style: italic; font-weight: 900; letter-spacing: -0.045em; line-height: 1; text-transform: uppercase; }
h1 span { color: var(--blue); }
.brand p { margin-top: 0.3rem; color: var(--muted); font-size: 0.9rem; }
.deal-meta { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); font-size: 0.8rem; text-align: right; }
.icon-button { flex: 0 0 44px; width: 44px; border: 1px solid var(--line-bright); border-radius: 8px; color: var(--blue-light); background: #10243a; font-size: 1.5rem; }

.game-grid { display: grid; grid-template-columns: minmax(0, 1fr) 17rem; gap: 1.5rem; padding: clamp(0.75rem, 3vw, 2.5rem); }
.table-area, .side-panel { min-width: 0; }
.control-panel { display: grid; grid-template-columns: 1fr 1fr minmax(8rem, 0.9fr); align-items: end; gap: 0.6rem 0.8rem; margin-bottom: 1.5rem; }
.mode-row { display: grid; gap: 0.35rem; min-width: 0; }
.mode-row label { color: var(--muted); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
select { width: 100%; padding: 0.4rem 0.55rem; border: 1px solid var(--line-bright); border-radius: 8px; color: var(--text); background: #0b1b2c; font-size: 0.9rem; }
.connection-status { grid-column: 1 / -1; color: var(--muted); font-size: 0.75rem; line-height: 1.4; }
.primary-button, .secondary-button, .skip-button, .hold-button { border-radius: 8px; padding: 0.5rem 0.7rem; font-weight: 850; line-height: 1.2; }
.primary-button, .skip-button { border: 1px solid #7bc5ff; color: #04111f; background: linear-gradient(#90d9ff, #2b8cff); box-shadow: 0 5px 15px #2b8cff18; }
.secondary-button { border: 1px solid var(--line-bright); color: var(--text); background: #10243a; }
.hold-button { border: 1px solid #ff8d83; color: #fff; background: linear-gradient(#e83e36, #ad211c); box-shadow: inset 0 1px #ffffff38, 0 5px 15px #9e1d1933; text-transform: uppercase; }
.skip-button { text-transform: uppercase; }
@media (hover: hover) { button:not(:disabled):hover { filter: brightness(1.12); } }

.section-title { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.8rem; }
.section-title h2 { font-size: clamp(1rem, 1.7vw, 1.4rem); font-weight: 800; }
.grid-icon { flex: 0 0 1rem; width: 1rem; height: 1rem; border-radius: 2px; background: conic-gradient(var(--blue) 25%, #15467e 0 50%, var(--blue) 0 75%, #15467e 0); box-shadow: 0 0 12px #2b8cff44; }
.practice-badge { margin-left: auto; padding: 0.2rem 0.45rem; border: 1px solid #36536e; border-radius: 4px; color: var(--blue-light); font-size: 0.65rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }

.card-row { --card-gap: clamp(0.35rem, 1.3vw, 1rem); overflow: hidden; padding-block: 1px; }
.card-track { display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 4 * var(--card-gap)) / 5); gap: var(--card-gap); transition: transform 420ms cubic-bezier(0.22, 0.8, 0.26, 1); }
.card-row.is-sliding .card-track { transform: translateX(calc(-1 * (((100% - 4 * var(--card-gap)) / 5) + var(--card-gap)))); }
.card-slot { min-width: 0; perspective: 900px; }
.card { position: relative; width: 100%; aspect-ratio: 0.64; transform-style: preserve-3d; transition: transform 260ms ease; }
.card.is-face-down { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; border-radius: 7px; backface-visibility: hidden; overflow: hidden; }
.front { padding: clamp(0.3rem, 0.85vw, 0.8rem); color: #121212; background: linear-gradient(135deg, #fff, #f7f7f3 65%, #e7e7e0); }
.back { transform: rotateY(180deg); border: 1px solid #ffffff66; background: repeating-linear-gradient(45deg, #ffffff10 0 2px, transparent 2px 8px), linear-gradient(135deg, #135fcb, #082e66); box-shadow: inset 0 0 0 4px #ffffff26; }
.corner { display: grid; justify-items: start; font-size: clamp(1.15rem, 3.2vw, 2.9rem); font-weight: 900; line-height: 0.9; }
.corner.bottom { align-self: end; transform: rotate(180deg); }
.pip { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: clamp(1.8rem, 5.5vw, 5rem); font-weight: 900; line-height: 1; }
.red-card { color: #b71614; }
.black-card { color: #111; }

.status-row { display: grid; grid-template-columns: minmax(5rem, 7.5rem) minmax(0, 1fr) 9rem; align-items: center; gap: clamp(0.6rem, 2vw, 1.8rem); margin-top: 1rem; }
.skip-button { width: 100%; min-height: 54px; font-size: 1.1rem; }
.deck-position { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.5rem; margin-bottom: 0.5rem; color: var(--muted); font-size: 0.95rem; }
.deck-position strong { color: var(--blue); font-size: 1.6em; }
.progress-track { height: 12px; overflow: hidden; border: 1px solid var(--line-bright); border-radius: 999px; background: #ffffff0d; }
.progress-track div { width: 0%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), #66c8ff); transition: width 180ms ease; }
.timer-dial { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.35rem; width: 9rem; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 50%; background: radial-gradient(circle, #0b1725 0 64%, transparent 65%), conic-gradient(var(--red) calc(var(--timer) * 1turn), #ffffff15 0); }
.hold-button { width: 75%; min-height: 48px; font-size: 1.05rem; }
.timer-dial strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.hint-row { display: flex; align-items: center; gap: 0.6rem; min-height: 2.5rem; margin-top: 0.4rem; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.info-icon { flex: 0 0 1.3rem; display: grid; place-items: center; height: 1.3rem; border: 1px solid var(--blue); border-radius: 50%; color: var(--blue-light); font-size: 0.8rem; font-weight: 800; }
.hand-panel { display: flex; align-items: center; gap: 0.7rem; min-height: 3.5rem; margin-top: 0.7rem; padding: 0.65rem 0.9rem; border: 1px solid var(--line-bright); border-radius: 8px; background: #0f1c2d99; color: var(--muted); font-size: 0.95rem; }
.hand-panel strong { color: #b9e9ff; }
.panel-suit { color: var(--blue); font-size: 1.7rem; line-height: 1; }
.is-final-five .section-title h2, .is-final-five .hint-row { color: var(--danger); }
.is-final-five .card-row { outline: 2px solid var(--red); outline-offset: 4px; border-radius: 5px; }
.is-final-five .progress-track div { background: linear-gradient(90deg, #c52f29, #ff8c81); }
.is-final-five .hand-panel { border-color: var(--red); }

.help-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.2rem 0.5rem; margin-top: 0.4rem; }
.text-button { padding: 0.25rem 0.1rem; border: 0; color: var(--blue-light); background: transparent; font-size: 0.85rem; text-decoration: underline; text-underline-offset: 3px; }
.motion-setting { display: flex; align-items: center; gap: 0.4rem; min-height: 44px; color: var(--muted); font-size: 0.8rem; cursor: pointer; }
.motion-setting input { width: 18px; height: 18px; margin: 0; accent-color: var(--blue); }
.keyboard-help { color: var(--muted); font-size: 0.75rem; line-height: 1.5; }
kbd { font-family: inherit; color: #d6e8fb; }
.side-panel { display: grid; align-content: start; gap: 1rem; }
.score-panel, .leaderboard-panel, .tutorial-panel { padding: 1rem; border: 1px solid var(--line); border-radius: 10px; background: linear-gradient(#111f31e8, #0a131fe8); }
.score-panel h2, .leaderboard-panel h2 { margin-bottom: 0.7rem; font-size: 1rem; }
dl, ol { margin: 0; padding: 0; }
dl div, .leaderboard-panel li { display: flex; justify-content: space-between; gap: 0.8rem; padding: 0.65rem 0; border-top: 1px solid #ffffff12; font-size: 0.85rem; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; font-weight: 800; overflow-wrap: anywhere; }
.leaderboard-panel ol { list-style: none; }
.panel-note { margin-bottom: 0.6rem; color: var(--muted); font-size: 0.8rem; line-height: 1.5; }
.leaderboard-panel li { color: var(--muted); line-height: 1.5; }
.tutorial-panel { margin-top: 1rem; border-color: #427eb3; }
.tutorial-panel h2 { margin-top: 0.4rem; font-size: 1.1rem; }
#tutorialText { margin-top: 0.65rem; color: var(--muted); line-height: 1.6; }
.tutorial-actions, .result-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-top: 1rem; }
.tutorial-actions > button, .result-actions > button { flex: 1 1 8rem; }

.result-panel { width: min(29rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow-y: auto; margin: auto; padding: 1.4rem; border: 1px solid var(--line-bright); border-radius: 14px; color: var(--text); background: #0b1929; box-shadow: 0 20px 80px #0009; }
.result-panel:not([open]) { display: none; }
.result-panel::backdrop { background: #02070dd4; backdrop-filter: blur(4px); }
.eyebrow { color: var(--blue-light); font-size: 0.75rem; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; }
#resultTitle { margin-top: 0.35rem; font-size: 1.8rem; }
#resultSummary, .regret-summary { margin-top: 0.8rem; color: var(--muted); font-size: 0.95rem; line-height: 1.55; }
.result-breakdown:not(:empty) { margin-top: 1rem; padding: 0.8rem; border: 1px solid var(--line); border-radius: 8px; line-height: 1.6; }
.share-fallback { width: 100%; min-height: 7rem; margin-top: 1rem; padding: 0.6rem; color: var(--text); background: #10243a; border: 1px solid var(--line-bright); border-radius: 8px; }

@media (max-width: 1000px) {
  .game-grid { grid-template-columns: minmax(0, 1fr); }
  .side-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .topbar { gap: 0.5rem; padding: 0.65rem 0.7rem; }
  .brand { gap: 0.35rem; }
  .brand-mark { font-size: 2.25rem; }
  h1 { font-size: clamp(1.2rem, 5.6vw, 1.8rem); }
  .brand p { margin-top: 0.2rem; font-size: 0.65rem; }
  .deal-meta { gap: 0.3rem; font-size: 0.6rem; }
  #utcStamp { max-width: 4.6rem; }
  .game-grid { gap: 1.15rem; padding: 0.75rem; }
  .control-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.4rem 0.55rem; margin-bottom: 0.8rem; }
  .control-panel > .primary-button { grid-column: 1 / -1; }
  .mode-row { gap: 0.25rem; }
  .mode-row label { font-size: 0.65rem; }
  select { font-size: 0.8rem; }
  .connection-status { font-size: 0.65rem; }
  .section-title { gap: 0.4rem; margin-bottom: 0.6rem; }
  .section-title h2 { font-size: 0.95rem; }
  .practice-badge { font-size: 0.6rem; }
  .card-row { --card-gap: 0.35rem; }
  .card { aspect-ratio: 0.61; }
  .corner { font-size: clamp(1.1rem, 5.2vw, 1.85rem); }
  .pip { font-size: clamp(1.6rem, 7vw, 2.6rem); }
  .front { padding: 0.3rem; }
  .card-face { border-radius: 5px; }
  .status-row { grid-template-columns: minmax(3.7rem, 0.8fr) minmax(0, 1.5fr) minmax(5rem, 1fr); gap: 0.6rem; margin-top: 0.75rem; }
  .skip-button { min-height: 48px; padding-inline: 0.3rem; font-size: 0.9rem; }
  .deck-position { justify-content: center; gap: 0; margin-bottom: 0.3rem; text-align: center; font-size: 0.7rem; }
  .deck-position > span { width: 100%; font-size: 0.65rem; }
  .deck-position strong { font-size: 1.55em; }
  .progress-track { height: 9px; }
  .timer-dial { width: 100%; aspect-ratio: auto; gap: 0.2rem; padding: 0 0 7px; border: 0; border-radius: 0; background: none; }
  .timer-dial::after { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; border-radius: 2px; background: linear-gradient(to right, var(--red) calc(var(--timer) * 100%), #ffffff20 0); content: ""; }
  .hold-button { width: 100%; min-height: 48px; padding-inline: 0.3rem; font-size: 0.9rem; }
  .timer-dial strong { font-size: 0.8rem; line-height: 1; }
  .hint-row { gap: 0.45rem; margin-top: 0.5rem; font-size: 0.75rem; }
  .hand-panel { min-height: 44px; margin-top: 0.45rem; padding: 0.5rem 0.6rem; font-size: 0.8rem; }
  .panel-suit { font-size: 1.35rem; }
  .help-row { margin-top: 0.1rem; }
  .side-panel { grid-template-columns: minmax(0, 1fr); }
  .score-panel, .leaderboard-panel { padding: 0.9rem; }
}

@media (max-height: 620px) and (max-width: 600px) {
  .topbar { padding-block: 0.35rem; }
  .game-grid { padding-top: 0.55rem; }
  .control-panel { margin-bottom: 0.6rem; }
  .status-row { margin-top: 0.6rem; }
  .hint-row { margin-top: 0.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after,
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}
