:root{
  --bg: #0b1220;
  --panel: rgba(255,255,255,0.06);
  --panel2: rgba(255,255,255,0.09);
  --text: #e9eefc;
  --muted: rgba(233,238,252,0.70);
  --border: rgba(233,238,252,0.12);
  --shadow: 0 18px 50px rgba(0,0,0,0.45);
  --red: #ff4d4d;
  --gold: #d4af37;
  --btn: rgba(255,255,255,0.10);
  --btnHover: rgba(255,255,255,0.14);
  --focus: rgba(212,175,55,0.45);
}

[data-theme="light"]{
  --bg: #f5f7fb;
  --panel: rgba(17,24,39,0.05);
  --panel2: rgba(17,24,39,0.08);
  --text: #0f172a;
  --muted: rgba(15,23,42,0.70);
  --border: rgba(15,23,42,0.12);
  --shadow: 0 18px 50px rgba(15,23,42,0.12);
  --btn: rgba(15,23,42,0.06);
  --btnHover: rgba(15,23,42,0.10);
  --focus: rgba(15,23,42,0.25);
}

*{ box-sizing: border-box; }

html, body{
  height: 100%;
  margin: 0;
  overflow: hidden; /* desktop stays no-scroll */
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(212,175,55,0.12), transparent 55%),
    radial-gradient(900px 600px at 85% 25%, rgba(255,77,77,0.08), transparent 60%),
    var(--bg);
  color: var(--text);
}

.app{
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
}

.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.brand{ display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo{
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  font-size: 22px;
  background: linear-gradient(180deg, rgba(212,175,55,0.22), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
}
.title{ font-weight: 900; letter-spacing: 0.2px; }
.subtitle{
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions{ display: flex; gap: 8px; }

.iconbtn{
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 14px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.content{
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

/* HUD */
.hud{
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.hud-card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.hud-label{ color: var(--muted); font-size: 12px; }
.hud-value{ margin-top: 4px; font-weight: 900; font-size: 18px; }
.hud-value.small{ font-weight: 800; font-size: 13px; color: var(--muted); }
.hud-mini{ margin-top: 6px; font-size: 12px; color: var(--muted); }

/* Table */
.table{
  min-height: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(0,0,0,0.0));
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-inner{
  height: 100%;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.table-sbs{
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr auto;
  align-items: stretch;
}
.seat{
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
}

.rowhead{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.rowtitle{ font-weight: 900; letter-spacing: 0.2px; }
.meta{ display: flex; align-items: center; gap: 10px; }

.badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(212,175,55,0.26), rgba(255,255,255,0.02));
  font-weight: 1000;
  font-size: 20px;
  letter-spacing: 0.3px;
}
.metatxt{ color: var(--muted); font-size: 12px; font-weight: 800; }

.hand{
  min-height: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 16px;
  border: 1px dashed rgba(255,255,255,0.12);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
[data-theme="light"] .hand{ border: 1px dashed rgba(15,23,42,0.14); }

.card{
  --cw: clamp(44px, 4.2vw, 66px);
  width: var(--cw);
  height: calc(var(--cw) * 1.42);
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.04));
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: clamp(6px, 0.7vw, 8px);
  box-shadow: 0 10px 22px rgba(0,0,0,0.20);
  flex: 0 0 auto;
}
.card .top, .card .bot{
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 900;
  font-size: clamp(10px, 1.0vw, 12px);
}
.card .mid{
  display: grid;
  place-items: center;
  font-size: clamp(20px, 2.1vw, 28px);
  font-weight: 900;
}
.card.red{ color: var(--red); }
.card.black{ color: var(--text); }
.card.back{
  background: repeating-linear-gradient(
    45deg,
    rgba(212,175,55,0.22),
    rgba(212,175,55,0.22) 8px,
    rgba(255,255,255,0.06) 8px,
    rgba(255,255,255,0.06) 16px
  );
}
.card.enter{ animation: pop .12s ease-out; }
@keyframes pop{
  from{ transform: translateY(4px); opacity: 0.0; }
  to{ transform: translateY(0px); opacity: 1.0; }
}

/* Status + Outcome */
.statusbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 2px;
}
.statusbar-span{ grid-column: 1 / -1; }
.statuswrap{ min-width: 0; display: grid; gap: 6px; }
.status{
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.outcome{
  display: none;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel2);
  font-weight: 1000;
  letter-spacing: 0.8px;
  font-size: 12px;
}
.outcome.show{ display: inline-flex; }
.outcome.win{ border-color: rgba(212,175,55,0.40); background: rgba(212,175,55,0.16); }
.outcome.lose{ border-color: rgba(255,77,77,0.40); background: rgba(255,77,77,0.12); }
.outcome.push{ border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.08); }
.outcome.bj{ border-color: rgba(212,175,55,0.55); background: rgba(212,175,55,0.22); }

.pill{
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel2);
  font-weight: 900;
  letter-spacing: 0.6px;
  font-size: 11px;
}

/* Controls */
.controls{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto auto;
  gap: 10px;
}
.bets{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
}
.chip{
  flex: 1 1 110px;
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
}

.actions{
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.btn{
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--text);
  padding: 12px 10px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 900;
}

.btn:not(.is-disabled):hover,
.chip:not(.is-disabled):hover,
.iconbtn:not(.is-disabled):hover{
  background: var(--btnHover);
  transform: translateY(-1px);
}
.btn:not(.is-disabled):active,
.chip:not(.is-disabled):active{
  transform: translateY(0px);
}

.btn.primary{
  border-color: rgba(212,175,55,0.35);
  background: linear-gradient(180deg, rgba(212,175,55,0.28), rgba(255,255,255,0.02));
}
.btn.danger{
  border-color: rgba(255,77,77,0.35);
  background: linear-gradient(180deg, rgba(255,77,77,0.18), rgba(255,255,0,0.00));
}

.is-disabled{
  opacity: 0.40;
  cursor: not-allowed;
  transform: none !important;
  filter: saturate(0.8);
}

.footer{ display: flex; justify-content: center; padding: 2px 0; }
.footnote{ font-size: 12px; color: var(--muted); }

/* Modal */
.modal{
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 10px;
  z-index: 50;
}
.modal.show{ display: flex; }
.modal-backdrop{ position: absolute; inset: 0; background: rgba(0,0,0,0.55); }

.modal-card{
  position: relative;
  width: min(820px, 96vw);
  border-radius: 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: min(92vh, 920px);

  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-head{
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.modal-title{ font-weight: 900; font-size: 16px; }
.modal-sub{ margin-top: 4px; font-size: 12px; color: var(--muted); }

.modal-body{
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 14px;
  overflow: auto;
}

.rules{
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 8px;
  font-size: 13px;
}
.modal-foot{
  flex: 0 0 auto;
  padding: 12px 14px 14px;
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* Settings */
.formgrid{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.field{
  display: grid;
  gap: 6px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
}
.field-label{ font-weight: 900; font-size: 13px; }
.field-help{ color: var(--muted); font-size: 12px; }
.input{
  width: 100%;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.12);
  color: var(--text);
  outline: none;
}
[data-theme="light"] .input{ background: rgba(15,23,42,0.05); }
.input:focus{ outline: 2px solid var(--focus); outline-offset: 2px; }

.field.switch{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.field.switch input{ width: 18px; height: 18px; }

.field.full{ grid-column: 1 / -1; }

.chipgrid{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.chipfield{ display: grid; gap: 6px; }
.chiplabel{ font-size: 12px; color: var(--muted); font-weight: 800; }

.settings-actions{
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.settings-actions .spacer{ flex: 1; }

/* Toast */
.toast{
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 60;
  display: none;
  width: min(560px, calc(100vw - 28px));
}
.toast.show{ display: block; }
.toast-card{
  position: relative;
  padding: 12px 44px 12px 12px;
  border-radius: 16px;
  background: var(--panel2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.toast-title{ font-weight: 950; letter-spacing: 0.2px; }
.toast-msg{ margin-top: 4px; color: var(--muted); font-size: 13px; }
.toast-x{
  position: absolute;
  top: 8px; right: 8px;
  width: 34px; height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--btn);
  color: var(--text);
  cursor: pointer;
}
.toast-x:hover{ background: var(--btnHover); }

@media (max-width: 920px){
  .hud{ grid-template-columns: repeat(2, minmax(0,1fr)); }
  .actions{ grid-template-columns: repeat(2, minmax(0,1fr)); }
  .formgrid{ grid-template-columns: 1fr; }
  .table-sbs{ grid-template-columns: 1fr; grid-template-rows: auto auto auto; }
  .statusbar-span{ grid-column: 1; }
  .field.full{ grid-column: 1; }
  .modal-card{ width: min(96vw, 760px); max-height: 92vh; }
}

/* ✅ Mobile: ALWAYS allow scrolling so cards never clip (15 mini etc) */
@media (max-width: 520px){
  html, body{
    height: auto;
    min-height: 100%;
    overflow-y: scroll;   /* ✅ ALWAYS scrollable */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .app{
    height: auto;
    min-height: 100dvh; /* still fills at least one screen */
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    gap: 10px;
  }

  /* stop forcing a "locked" middle section that can clip on iOS */
  .content{
    flex: 0 0 auto;
    min-height: unset;
    grid-template-rows: auto auto auto;
    gap: 10px;
  }

  .table-inner{
    height: auto;
    padding: 10px;
    gap: 8px;
  }
  .seat{
    min-height: unset;
    grid-template-rows: auto auto;
  }

  /* tiny tighten so you usually only need a small scroll */
  .topbar{ padding: 8px 10px; border-radius: 14px; }
  .logo{ width: 38px; height: 38px; border-radius: 12px; font-size: 20px; }
  .iconbtn{ width: 36px; height: 36px; border-radius: 12px; }

  .hud{ gap: 8px; }
  .hud-card{ padding: 8px 10px; border-radius: 14px; }
  .hud-value{ font-size: 16px; }

  .badge{ min-width: 56px; height: 36px; padding: 0 12px; font-size: 18px; }
  .hand{ padding: 8px; gap: 8px; }

  .card{
    --cw: clamp(36px, 9vw, 54px);
    border-radius: 12px;
    padding: 6px;
  }
  .card .mid{ font-size: clamp(18px, 5vw, 24px); }

  .controls{ padding: 8px; border-radius: 16px; gap: 8px; }
  .chip{ padding: 9px 10px; border-radius: 12px; }
  .btn{ padding: 11px 10px; border-radius: 12px; }
}