:root {
  --bg: #0e0f12;
  --bg-2: #14151a;
  --ink: #efe9dd;
  --ink-dim: #a8a29a;
  --ink-faint: #5e5b56;
  --rule: rgba(239,233,221,.10);
  --rule-strong: rgba(239,233,221,.18);
  --accent: #d4a259;
  --accent-soft: #e8c98a;
  --red: #c9514c;
  --red-soft: #e07b78;
  --black: #2a2620;
  --felt: #1a3a2e;
  --felt-2: #102420;
  --card: #f6f1e6;
  --card-edge: #c8bfa7;
  --shadow-1: 0 1px 0 rgba(0,0,0,.35), 0 6px 14px rgba(0,0,0,.35);
  --shadow-2: 0 2px 0 rgba(0,0,0,.4), 0 16px 38px rgba(0,0,0,.55);
  --serif: 'Fraunces', 'Instrument Serif', Georgia, serif;
  --display: 'Instrument Serif', 'Fraunces', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --anim: 220ms;
  --ease: cubic-bezier(.2,.7,.2,1);
  --card-w: 124px;
  --card-h: 180px;
  --card-r: 8px;
  --tableau-spread: 38px;
  --tableau-spread-down: 19px;
}
.theme-day {
  --bg: #f3eee2; --bg-2: #ebe4d2; --ink: #221f1a; --ink-dim: #5a564d; --ink-faint: #8a857a;
  --rule: rgba(34,31,26,.12); --rule-strong: rgba(34,31,26,.22);
  --accent: #8a5a1c; --accent-soft: #b8842d; --red: #a8332c; --red-soft: #b8453d;
  --black: #1a1611; --felt: #2c5742; --felt-2: #1f4030; --card: #fbf6ea; --card-edge: #b9ad8c;
}
.felt-emerald { --felt: #1a3a2e; --felt-2: #102420; }
.felt-burgundy{ --felt: #3a1a22; --felt-2: #220f15; }
.felt-midnight{ --felt: #16223a; --felt-2: #0d1424; }
.felt-charcoal{ --felt: #1c1d20; --felt-2: #101115; }
.felt-paper   { --felt: #e6dfcc; --felt-2: #d4ccb4; --ink: #221f1a; --ink-dim: #5a564d; --rule: rgba(34,31,26,.12); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--serif);
  font-feature-settings: "ss01","liga","kern","onum";
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  min-height: 100dvh; overflow: hidden; user-select: none;
}
.app {
  display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh;
  background:
    radial-gradient(ellipse 90% 60% at 50% 30%, color-mix(in oklab, var(--felt) 92%, white 0%), var(--felt-2) 75%),
    var(--felt-2);
  position: relative;
}
.app::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(rgba(255,255,255,.02) 1px, transparent 1px),
    radial-gradient(rgba(0,0,0,.03) 1px, transparent 1px);
  background-size: 3px 3px, 5px 5px; background-position: 0 0, 1px 2px;
  pointer-events: none; mix-blend-mode: overlay; opacity: .55;
}

.brandbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 22px; border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, rgba(0,0,0,.25), rgba(0,0,0,0)); position: relative; z-index: 200;
}
.brandbar .left { display: flex; align-items: center; gap: 14px; color: var(--ink-dim); font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.brandbar .brand { color: var(--ink); font-family: var(--display); font-style: italic; font-size: 18px; letter-spacing: .01em; text-transform: none; }
.brandbar .crumb { opacity: .7; }
.brandbar .right { display: flex; gap: 8px; align-items: center; }
.iconbtn {
  appearance: none; border: 1px solid var(--rule-strong); background: transparent; color: var(--ink-dim);
  width: 30px; height: 30px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  transition: color var(--anim), border-color var(--anim), background var(--anim);
}
.iconbtn:hover { color: var(--ink); border-color: var(--ink-dim); }
.iconbtn svg { width: 14px; height: 14px; }

.masthead {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 24px;
  padding: 18px 28px 16px; border-bottom: 1px solid var(--rule); position: relative; z-index: 4;
}
.masthead .title h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(28px, 3.6vw, 44px); letter-spacing: -0.01em; line-height: 1; color: var(--ink); }
.masthead .title h1 em { color: var(--accent); font-style: italic; }
.masthead .title .sub { margin-top: 6px; color: var(--ink-dim); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .18em; display: flex; gap: 10px; align-items: center; }
.masthead .title .sub .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); display: inline-block; }
.hud { display: flex; gap: 0; align-items: stretch; border: 1px solid var(--rule-strong); border-radius: 2px; background: rgba(0,0,0,.18); backdrop-filter: blur(6px); overflow: hidden; }
.hud .stat { padding: 8px 18px; display: flex; flex-direction: column; align-items: center; gap: 2px; border-right: 1px solid var(--rule); min-width: 84px; }
.hud .stat:last-child { border-right: 0; }
.hud .stat .k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-faint); }
.hud .stat .v { font-family: var(--display); font-size: 22px; line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums; }
.toolbar { display: flex; gap: 6px; justify-self: end; align-items: center; }
.tbtn {
  appearance: none; cursor: pointer; border: 1px solid var(--rule-strong); background: rgba(0,0,0,.18);
  color: var(--ink); font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  padding: 8px 12px; border-radius: 2px;
  transition: background var(--anim), border-color var(--anim), color var(--anim), transform var(--anim);
  display: inline-flex; align-items: center; gap: 6px;
}
.tbtn:hover { border-color: var(--ink-dim); background: rgba(0,0,0,.30); }
.tbtn:active { transform: translateY(1px); }
.tbtn.primary { background: var(--accent); border-color: var(--accent); color: #1a1611; }
.tbtn.primary:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
.tbtn.ghost { background: transparent; }
.tbtn[disabled] { opacity: .35; cursor: not-allowed; }
.tbtn svg { width: 12px; height: 12px; }
.tbtn .kbd { color: var(--ink-faint); font-size: 10px; margin-left: 2px; }

.table-wrap { position: relative; overflow: hidden; display: flex; align-items: flex-start; justify-content: center; padding: 22px 28px 18px; }
.table { position: relative; width: 100%; max-width: 1200px; }
.row-top, .row-tableau { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--col-gap, 18px); align-items: start; }
.row-top { margin-bottom: 22px; }
.col { position: relative; min-height: calc(var(--card-h) + 10px); }

.pile { position: relative; width: var(--card-w); height: var(--card-h); margin: 0 auto; }
.pile-tableau { position: relative; width: var(--card-w); margin: 0 auto; min-height: var(--card-h); }
.empty-slot {
  width: var(--card-w); height: var(--card-h); border-radius: var(--card-r);
  border: 1.5px dashed var(--rule-strong); background: rgba(0,0,0,.10);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-faint); font-family: var(--display); font-size: 28px; font-style: italic;
  transition: border-color var(--anim), background var(--anim);
}
.empty-slot.target { border-color: var(--accent); background: rgba(212,162,89,.10); color: var(--accent); }
.empty-slot.foundation { font-size: 18px; }
.empty-slot.stock-empty { cursor: pointer; }
.empty-slot.stock-empty:hover { border-color: var(--accent); color: var(--accent); }

.card {
  position: absolute; left: 0; top: 0; width: var(--card-w); height: var(--card-h);
  border-radius: var(--card-r); background: var(--card); box-shadow: var(--shadow-1); cursor: pointer;
  transition: top var(--anim) var(--ease), left var(--anim) var(--ease), transform var(--anim) var(--ease), box-shadow var(--anim);
  will-change: transform; overflow: hidden;
}
.card.face-down { background: #2a1418; border: 1px solid rgba(0,0,0,.25); }
.card.face-up { border: 1px solid var(--card-edge); background: linear-gradient(180deg, rgba(255,255,255,.7), rgba(255,255,255,0) 30%), var(--card); }
.card.red { color: var(--red); }
.card.black { color: var(--black); }
.card.selected { box-shadow: 0 0 0 2px var(--accent), var(--shadow-2); transform: translateY(-3px); }
.card.dragging { z-index: 9999; box-shadow: var(--shadow-2); transition: none; transform: rotate(1.5deg) scale(1.02); }
.card.target-glow { box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-2); }
.card.invalid-shake { animation: shake .35s var(--ease); }
@keyframes shake { 0%,100%{transform:translateX(0);}20%{transform:translateX(-4px);}40%{transform:translateX(4px);}60%{transform:translateX(-2px);}80%{transform:translateX(2px);} }
.card.hint-pulse { animation: hintpulse 1s ease-in-out 2; }
@keyframes hintpulse { 0%,100%{box-shadow:var(--shadow-1);}50%{box-shadow:0 0 0 3px var(--accent), 0 0 24px var(--accent), var(--shadow-2);} }

.face { position: absolute; inset: 0; display: grid; grid-template-rows: auto 1fr auto; padding: 6px 8px; font-family: var(--serif); }
.face .corner { display: flex; flex-direction: column; line-height: 1; align-items: center; }
.face .corner.tl { justify-self: start; }
.face .corner.br { justify-self: end; transform: rotate(180deg); }
.face .corner .rank { font-family: var(--display); font-size: 24px; font-weight: 500; letter-spacing: -0.02em; }
.face .corner .suit { font-size: 16px; margin-top: 1px; }
.face .center { display: flex; align-items: center; justify-content: center; font-size: 52px; filter: drop-shadow(0 1px 0 rgba(0,0,0,.05)); }
.face-style-pip .center { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: repeat(7,1fr); gap:0; width:100%; height:100%; font-size:18px; }
.face-style-pip .center .pip { display: flex; align-items: center; justify-content: center; font-size: 22px; }
.face-style-pip .center .pip.flip { transform: rotate(180deg); }
.face-style-pip .center .pip.court { font-family: var(--display); font-style: italic; font-size: 60px; font-weight: 500; grid-column: 1/-1; grid-row: 1/-1; display: flex; align-items: center; justify-content: center; }
.face-style-editorial .center { font-family: var(--display); font-size: 88px; font-style: italic; line-height: 1; letter-spacing: -.04em; }
.face-style-minimal .center { font-size: 58px; }
.face-style-minimal .corner .rank { font-family: var(--mono); font-size: 18px; font-weight: 600; letter-spacing: 0; }

/* Classic — high readability: bold sans rank, larger suit symbol in corner, full pip body */
.face-style-classic { padding: 4px 6px; }
.face-style-classic .corner .rank { font-family: var(--mono); font-size: 22px; font-weight: 700; letter-spacing: 0; line-height: 1; }
.face-style-classic .corner .suit { font-size: 21px; margin-top: 2px; line-height: 1; }
.face-style-classic .center { padding: 0; position: relative; }
.cl-pips { position: absolute; inset: 8% 12%; }
.cl-pip { position: absolute; transform: translate(-50%, -50%); font-size: 30px; line-height: 1; }
.cl-pip.flip { transform: translate(-50%, -50%) rotate(180deg); }
.cl-ace { font-size: 76px; line-height: 1; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.cl-court { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; gap: 2px; }
.cl-court-letter { font-family: var(--mono); font-size: 60px; font-weight: 700; line-height: .9; letter-spacing: -.02em; }
.cl-court-suit { font-size: 32px; line-height: 1; }

/* Smaller cards: scale down classic pips proportionally */
@media (max-width: 1080px) {
  .face-style-classic .corner .rank { font-size: 14px; }
  .face-style-classic .corner .suit { font-size: 13px; }
  .cl-pip { font-size: 18px; }
  .cl-ace { font-size: 44px; }
  .cl-court-letter { font-size: 34px; }
  .cl-court-suit { font-size: 20px; }
}
@media (max-width: 760px) {
  .face-style-classic .corner .rank { font-size: 12px; }
  .face-style-classic .corner .suit { font-size: 11px; }
  .cl-pip { font-size: 14px; }
  .cl-ace { font-size: 32px; }
  .cl-court-letter { font-size: 26px; }
  .cl-court-suit { font-size: 16px; }
}
.foundation-ghost { font-size: 30px; opacity: .45; font-family: var(--display); }

.stock-cluster { display: flex; gap: 14px; align-items: flex-start; }
.waste-pile { position: relative; width: calc(var(--card-w) + var(--tableau-spread)*2); height: var(--card-h); }
.waste-pile .card { transition: left var(--anim) var(--ease), top var(--anim) var(--ease), opacity var(--anim); }
.foundation-row { display: flex; gap: var(--col-gap, 18px); margin-left: auto; }
.row-top-grid { display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 24px; margin-bottom: 22px; }

.statusbar {
  display: flex; justify-content: space-between; align-items: center; padding: 8px 22px;
  border-top: 1px solid var(--rule);
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .15em; text-transform: uppercase; color: var(--ink-faint);
  background: rgba(0,0,0,.20); z-index: 5;
}
.statusbar .l, .statusbar .r { display: flex; gap: 16px; align-items: center; }
.statusbar .ok { color: var(--accent); }
.statusbar .pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; box-shadow: 0 0 6px var(--accent); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:.5;}50%{opacity:1;} }
.kbd-key { display: inline-block; padding: 1px 5px; font-family: var(--mono); font-size: 10px; border: 1px solid var(--rule-strong); border-radius: 3px; color: var(--ink-dim); margin: 0 2px; }

.win-overlay {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 50%, rgba(0,0,0,.6), rgba(0,0,0,.85));
  backdrop-filter: blur(10px); display: flex; align-items: center; justify-content: center;
  z-index: 100; animation: fadeIn .5s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.win-card {
  background: var(--bg-2); border: 1px solid var(--rule-strong); border-radius: 4px;
  padding: 40px 56px; text-align: center; max-width: 460px; position: relative; overflow: hidden;
}
.win-card .eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .25em; text-transform: uppercase; color: var(--accent); margin-bottom: 12px; }
.win-card h2 { font-family: var(--display); font-style: italic; font-weight: 400; font-size: 60px; line-height: 1; margin: 0 0 20px; color: var(--ink); letter-spacing: -.02em; }
.win-card .stats { display: flex; justify-content: center; gap: 28px; margin-bottom: 28px; }
.win-card .stats .s { display: flex; flex-direction: column; gap: 2px; }
.win-card .stats .k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-faint); }
.win-card .stats .v { font-family: var(--display); font-size: 28px; color: var(--ink); }
.win-card .actions { display: flex; gap: 8px; justify-content: center; }

.no-moves {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  background: var(--bg-2); border: 1px solid var(--rule-strong);
  padding: 12px 22px; border-radius: 2px; display: flex; align-items: center; gap: 14px; z-index: 50;
  animation: rise .3s var(--ease) both;
}
@keyframes rise { from{transform:translate(-50%,12px);opacity:0;}to{transform:translate(-50%,0);opacity:1;} }
.no-moves .label { font-family: var(--display); font-style: italic; font-size: 18px; color: var(--ink); }

.shower-card { position: fixed; width: 36px; height: 52px; border-radius: 4px; pointer-events: none; z-index: 90; }
.drag-layer { position: fixed; inset: 0; pointer-events: none; z-index: 9000; }

/* Settings menu */
.settings-menu {
  position: absolute; top: 38px; right: 0;
  background: var(--bg-2); border: 1px solid var(--rule-strong); border-radius: 3px;
  min-width: 280px; z-index: 9999;
  box-shadow: 0 16px 40px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.04) inset;
  padding: 6px 0; font-family: var(--mono);
  animation: rise .18s var(--ease) both;
}
.settings-header { padding: 10px 16px 8px; font-size: 10px; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-faint); border-bottom: 1px solid var(--rule); }
.settings-row { padding: 12px 16px; border-bottom: 1px solid var(--rule); display: flex; flex-direction: column; gap: 8px; }
.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-dim); display: flex; align-items: center; gap: 8px; }
.settings-badge { font-size: 8.5px; letter-spacing: .2em; padding: 2px 6px; border: 1px solid var(--rule-strong); border-radius: 1px; color: var(--accent); }
.settings-segments { display: flex; gap: 0; border: 1px solid var(--rule-strong); border-radius: 2px; overflow: hidden; }
.settings-seg { flex: 1; padding: 7px 8px; background: transparent; border: none; border-right: 1px solid var(--rule); color: var(--ink-dim); font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; cursor: pointer; transition: background var(--anim), color var(--anim); }
.settings-seg:last-child { border-right: none; }
.settings-seg:hover { background: rgba(255,255,255,.04); color: var(--ink); }
.settings-seg.active { background: var(--accent); color: #1a1611; }
.settings-toggle { width: 40px; height: 22px; border-radius: 11px; border: 1px solid var(--rule-strong); background: rgba(0,0,0,.3); cursor: pointer; padding: 0; position: relative; transition: background var(--anim); align-self: flex-start; }
.settings-toggle.on { background: var(--accent); border-color: var(--accent); }
.settings-toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); transition: left var(--anim) var(--ease); }
.settings-toggle.on .settings-toggle-thumb { left: 20px; background: #1a1611; }
.settings-confirm { padding: 14px 16px; background: rgba(212,162,89,.06); border-top: 1px solid var(--accent); }
.settings-confirm-title { font-family: var(--display); font-style: italic; font-size: 18px; color: var(--ink); margin-bottom: 4px; }
.settings-confirm-body { font-size: 11px; color: var(--ink-dim); line-height: 1.5; margin-bottom: 12px; letter-spacing: 0; text-transform: none; }
.settings-confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }

.hide-hud .hud { display: none; }
.hide-hud .statusbar { display: none; }

@media (max-width: 1180px) {
  .masthead { gap: 14px; padding: 14px 20px 12px; }
  .hud .stat { padding: 6px 12px; min-width: 64px; }
  .hud .stat .v { font-size: 18px; }
  .tbtn { padding: 7px 10px; font-size: 10px; }
  .tbtn .kbd { display: none; }
}
@media (max-width: 1080px) {
  :root { --card-w: 78px; --card-h: 114px; --tableau-spread: 24px; --tableau-spread-down: 12px; }
  .row-top, .row-tableau { gap: 12px; }
  .table-wrap { padding: 14px 16px; }
  .masthead { grid-template-columns: 1fr auto; }
  .masthead .toolbar { grid-column: 1 / -1; justify-self: stretch; flex-wrap: wrap; padding-top: 4px; border-top: 1px dashed var(--rule); }
}
@media (max-width: 760px) {
  :root { --card-w: 56px; --card-h: 82px; --tableau-spread: 18px; --tableau-spread-down: 9px; }
  .toolbar .tbtn { padding: 6px 9px; font-size: 10px; }
  .masthead { grid-template-columns: 1fr auto; padding: 12px 14px; gap: 8px; }
  .masthead .toolbar { grid-column: 1 / -1; justify-self: stretch; flex-wrap: wrap; }
  .hud .stat { padding: 6px 10px; min-width: 60px; }
  .hud .stat .v { font-size: 16px; }
}
