/* Svit — midnight casino deco */

@font-face {
  font-family: 'Limelight';
  src: url('../assets/limelight.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

:root {
  --felt-hi: #173a2b;
  --felt: #123324;
  --felt-lo: #0a1f16;
  --line: rgba(217, 169, 74, 0.28);
  --gold: #d9a94a;
  --gold-hi: #f0cd7e;
  --bone: #f4eee0;
  --bone-shadow: #d8cfb8;
  --ink: #232936;
  --red: #c94f4f;
  --card-back: #6e2432;
  --card-back-line: #94404d;
  --bust: #e05252;
  --card-w: clamp(38px, calc((100vw - 16px - 6 * 5px) / 7), 62px);
  --card-h: calc(var(--card-w) * 1.42);
  --radius: calc(var(--card-w) * 0.12);
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(140% 90% at 50% 0%, var(--felt) 0%, var(--felt-lo) 78%),
    var(--felt-lo);
  color: var(--bone);
  font-family: 'Avenir Next', 'Segoe UI', 'Helvetica Neue', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  display: flex;
  justify-content: center;
}

/* subtle felt grain */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: repeating-conic-gradient(rgba(255,255,255,0.6) 0% 25%, transparent 0% 50%);
  background-size: 3px 3px;
}

#app {
  width: 100%;
  max-width: 470px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(env(safe-area-inset-top), 8px) 8px calc(env(safe-area-inset-bottom) + 8px);
  position: relative;
}

/* ---------- top bar ---------- */

#topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 4px 2px 10px;
}

.wordmark {
  font-family: 'Limelight', cursive;
  font-weight: 400;
  font-size: 1.7rem;
  letter-spacing: 0.06em;
  color: var(--gold);
  text-shadow: 0 1px 0 rgba(0,0,0,0.5);
  line-height: 1;
}

#score-wrap {
  margin-left: auto;
  text-align: right;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.score-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: rgba(244, 238, 224, 0.55);
}

#score {
  font-size: 1.55rem;
  font-variant-numeric: tabular-nums;
  color: var(--gold-hi);
  font-weight: 600;
  line-height: 1;
  transition: transform 0.15s ease;
}

#score.bump { animation: scoreBump 0.45s ease; }
@keyframes scoreBump {
  30% { transform: scale(1.22); color: #fff; }
}

.icon-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--bone);
  font-size: 1rem;
  width: 34px;
  height: 34px;
  align-self: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:disabled { opacity: 0.3; cursor: default; }

/* ---------- board ---------- */

#board {
  display: grid;
  grid-template-columns: repeat(7, var(--card-w));
  justify-content: space-between;
  gap: 5px;
  padding: 2px 0 6px;
  min-height: calc(var(--card-h) + 3 * (var(--card-w) * 0.30) + 8px);
  align-items: start;
  /* centre the tableau in whatever vertical space the screen offers */
  margin: auto 0;
}

.column {
  position: relative;
  height: calc(var(--card-h) + 3 * (var(--card-w) * 0.30));
}

.column .card {
  position: absolute;
  left: 0;
}

/* ---------- cards ---------- */

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  border: none;
  padding: 0;
  cursor: default;
  font-family: inherit;
}

.card.face-up {
  background: linear-gradient(168deg, #faf6ea 0%, var(--bone) 55%, #e9e1cd 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.35) inset,
    0 -2px 4px rgba(120, 105, 70, 0.25) inset,
    0 3px 5px rgba(0, 0, 0, 0.45);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  position: relative;
}

.card.face-up .rank {
  font-size: calc(var(--card-w) * 0.42);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}

.card.face-up .suit {
  font-size: calc(var(--card-w) * 0.40);
  line-height: 1.05;
}

.card.red { color: var(--red); }

.card.face-down {
  background:
    repeating-linear-gradient(45deg,
      var(--card-back) 0 5px,
      var(--card-back-line) 5px 6px);
  box-shadow:
    0 0 0 2px rgba(0,0,0,0.15) inset,
    0 2px 4px rgba(0, 0, 0, 0.5);
  border: 2px solid #57202b;
}

.card.playable {
  cursor: pointer;
  box-shadow:
    0 0 0 2px var(--gold) ,
    0 1px 0 rgba(255,255,255,0.35) inset,
    0 4px 9px rgba(0, 0, 0, 0.55);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  50% { box-shadow: 0 0 0 2px var(--gold-hi), 0 0 14px rgba(217,169,74,0.35), 0 4px 9px rgba(0,0,0,0.55); }
}

.card.playable:active { transform: scale(0.94); }

/* card being removed from the board */
.card.taking {
  animation: takeUp 0.22s ease forwards;
  pointer-events: none;
}
@keyframes takeUp {
  to { transform: translateY(26px) scale(0.5); opacity: 0; }
}

/* newly revealed card */
.card.revealed { animation: flipIn 0.3s ease; }
@keyframes flipIn {
  from { transform: rotateY(90deg); }
}

/* ---------- tutorial coach ---------- */

#coach {
  margin: 0 2px 10px;
  padding: 12px 14px 8px;
  border: 1px solid var(--gold);
  border-radius: 12px;
  background: linear-gradient(175deg, rgba(23, 58, 43, 0.95), rgba(13, 36, 25, 0.95));
  box-shadow: 0 6px 18px rgba(0,0,0,0.45), 0 0 0 1px rgba(240,205,126,0.12);
  animation: coachIn 0.3s ease;
}

@keyframes coachIn {
  from { transform: translateY(8px); opacity: 0; }
}

#coach p {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--bone);
}

#coach b { color: var(--gold-hi); }
.s-red { color: var(--red); }
.s-black { color: inherit; }
#overlay-panel .s-red { color: var(--red); }

#coach-skip {
  background: none;
  border: none;
  color: rgba(244, 238, 224, 0.45);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 0 2px;
  cursor: pointer;
}

.coach-glow {
  animation: coachGlow 1.6s ease-in-out infinite !important;
}

@keyframes coachGlow {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold); }
  50% { box-shadow: 0 0 0 3px var(--gold-hi), 0 0 18px rgba(217, 169, 74, 0.55); }
}

/* ---------- chain zone ---------- */

#chain-zone {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 2px;
  position: relative;
  min-height: calc(var(--card-h) * 0.9 + 22px);
}

#chain-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#chain-cards {
  flex: 1;
  display: flex;
  align-items: center;
  min-height: calc(var(--card-h) * 0.9);
  overflow: hidden;
  justify-content: flex-end;
  padding-right: 4px;
}

#chain-cards .card {
  --card-w: clamp(30px, 9vw, 46px);
  flex: none;
  margin-left: calc(var(--card-w) * -0.34);
  transition: margin 0.2s ease;
}

#chain-cards .card:first-child { margin-left: 0; }

#chain-cards .card.chain-top {
  --card-w: clamp(40px, 12vw, 58px);
  margin-left: 6px;
  z-index: 2;
}

#chain-cards .card.pop { animation: popIn 0.24s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes popIn {
  from { transform: scale(0.4) translateY(14px); opacity: 0; }
}

#chain-cards.busting .card { animation: scatter 0.5s ease forwards; }
@keyframes scatter {
  30% { transform: translateX(-4px) rotate(-4deg); }
  60% { transform: translateX(4px) rotate(4deg); opacity: 0.8; }
  100% { transform: translateY(40px) rotate(10deg); opacity: 0; }
}

#chain-value-wrap {
  min-width: 74px;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

#chain-points {
  font-size: 1.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--bone);
}

#chain-points.hot { color: var(--gold-hi); text-shadow: 0 0 12px rgba(217,169,74,0.55); }

.mult-chip {
  font-family: 'Limelight', cursive;
  font-size: 0.95rem;
  color: var(--felt-lo);
  background: radial-gradient(circle at 50% 35%, var(--gold-hi), var(--gold) 70%);
  border-radius: 999px;
  padding: 3px 9px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5), 0 0 0 2px rgba(240, 205, 126, 0.35);
}

.mult-chip.pulse { animation: chipPulse 0.5s ease; }
@keyframes chipPulse {
  40% { transform: scale(1.35) rotate(-6deg); }
}

/* toast messages (bust / ride win / clean sweep) */
#toast {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: 'Limelight', cursive;
  font-size: 1.5rem;
  letter-spacing: 0.08em;
  opacity: 0;
}

#toast.show-win { animation: toastIn 1.1s ease; color: var(--gold-hi); }
#toast.show-bust { animation: toastIn 1.1s ease; color: var(--bust); }
@keyframes toastIn {
  8% { opacity: 1; transform: scale(1.06); }
  25% { transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

#app.shake { animation: shake 0.4s ease; }
@keyframes shake {
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

/* ---------- action rail ---------- */

#rail {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  gap: 8px;
  padding: 12px 0 4px;
}

#rail button {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--bone);
  padding: 10px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

#rail button:active:not(:disabled) { transform: scale(0.96); }
#rail button:disabled { opacity: 0.28; cursor: default; }

.ride-btn .ride-arrow { font-size: 0.85rem; color: var(--gold); }
.ride-btn .ride-word {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.68rem;
}
.ride-btn .ride-odds {
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--gold-hi);
}

#bank-btn {
  background: linear-gradient(170deg, rgba(217,169,74,0.22), rgba(217,169,74,0.08)) !important;
  border-color: var(--gold) !important;
}

#bank-btn .bank-word {
  font-family: 'Limelight', cursive;
  font-size: 1.25rem;
  letter-spacing: 0.1em;
  color: var(--gold-hi);
  line-height: 1.1;
}

#bank-btn .bank-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--bone);
  min-height: 1em;
}

#stock-line {
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(244, 238, 224, 0.45);
  padding: 6px 0 2px;
}

/* ---------- overlay ---------- */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 8, 0.78);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}

#overlay[hidden] { display: none; }

#overlay-panel {
  background: linear-gradient(175deg, #16382a, #0d2419);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-width: 380px;
  width: 100%;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 22px 22px 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.6);
  animation: panelIn 0.28s cubic-bezier(0.2, 1.3, 0.4, 1);
}

@keyframes panelIn {
  from { transform: translateY(26px) scale(0.96); opacity: 0; }
}

#overlay-panel h2 {
  font-family: 'Limelight', cursive;
  font-weight: 400;
  color: var(--gold);
  font-size: 1.5rem;
  margin-bottom: 12px;
  letter-spacing: 0.05em;
}

#overlay-panel p, #overlay-panel li {
  font-size: 0.88rem;
  line-height: 1.5;
  color: rgba(244, 238, 224, 0.88);
  margin-bottom: 8px;
}

#overlay-panel ul { list-style: none; margin-bottom: 10px; }
#overlay-panel li { padding-left: 1.1em; position: relative; }
#overlay-panel li::before {
  content: '♦';
  position: absolute;
  left: 0;
  color: var(--gold);
  font-size: 0.75em;
  top: 0.25em;
}

#overlay-panel .final-score {
  font-size: 2.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold-hi);
  text-align: center;
  line-height: 1.1;
}

#overlay-panel .final-label {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  font-size: 0.65rem;
  color: rgba(244,238,224,0.55);
  margin-bottom: 2px;
}

#overlay-panel .badge {
  text-align: center;
  font-family: 'Limelight', cursive;
  color: var(--gold-hi);
  margin: 6px 0 2px;
}

#overlay-panel .record {
  text-align: center;
  color: var(--gold-hi);
  font-weight: 600;
  margin: 4px 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  margin: 14px 0;
}

.stat-grid div {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: rgba(244,238,224,0.85);
  border-bottom: 1px dotted rgba(217,169,74,0.2);
  padding-bottom: 3px;
}

.stat-grid b { font-variant-numeric: tabular-nums; color: var(--bone); }

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.overlay-actions button {
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  cursor: pointer;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--bone);
  font-family: inherit;
  letter-spacing: 0.04em;
}

.overlay-actions button.primary {
  background: linear-gradient(170deg, var(--gold-hi), var(--gold));
  color: #201703;
  border: none;
  font-weight: 700;
}

.deal-id {
  text-align: center;
  font-size: 0.68rem;
  color: rgba(244,238,224,0.4);
  margin-top: 12px;
  font-variant-numeric: tabular-nums;
}

/* score fly */
.fly-points {
  position: fixed;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold-hi);
  font-size: 1.3rem;
  pointer-events: none;
  z-index: 15;
  animation: fly 0.7s ease forwards;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}

@keyframes fly {
  to { transform: translate(var(--fly-x), var(--fly-y)) scale(0.55); opacity: 0; }
}

/* landscape / desktop nicety: keep the table centred with felt around */
@media (min-width: 500px) {
  #app {
    border-left: 1px solid rgba(217,169,74,0.15);
    border-right: 1px solid rgba(217,169,74,0.15);
    box-shadow: 0 0 80px rgba(0,0,0,0.5);
  }
}
