:root {
  color-scheme: dark;
  --bg: #082b24;
  --bg-deep: #051f1a;
  --surface: rgba(255, 255, 255, 0.085);
  --surface-strong: rgba(255, 255, 255, 0.13);
  --line: rgba(255, 255, 255, 0.13);
  --text: #fffaf0;
  --muted: #bfd0c9;
  --accent: #e8c66a;
  --accent-strong: #f3d885;
  --danger: #e56f65;
  --success: #67c792;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --radius: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; margin: 0; }
body {
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% -10%, rgba(232, 198, 106, 0.18), transparent 34%),
    radial-gradient(circle at 10% 80%, rgba(255,255,255,0.07), transparent 30%),
    linear-gradient(160deg, #123f35 0%, var(--bg) 48%, var(--bg-deep) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(232, 198, 106, 0.55); outline-offset: 3px; }

.app-shell {
  min-height: 100dvh;
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
}
.screen {
  width: min(100%, 620px);
  min-height: calc(100dvh - 36px - var(--safe-top) - var(--safe-bottom));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.center-screen { justify-content: center; align-items: center; text-align: center; }

.brand-lockup { display: grid; justify-items: center; gap: 20px; }
.brand-mark { position: relative; width: 118px; height: 112px; }
.play-card {
  position: absolute;
  width: 73px;
  height: 102px;
  border-radius: 12px;
  background: #fffaf0;
  box-shadow: 0 16px 38px rgba(0,0,0,.25);
  border: 2px solid rgba(0,0,0,.08);
}
.play-card::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 7px;
  background:
    linear-gradient(45deg, transparent 44%, rgba(255,255,255,.22) 45% 55%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, rgba(255,255,255,.18) 45% 55%, transparent 56%),
    #b54845;
  background-size: 13px 13px;
}
.play-card.one { left: 14px; top: 8px; transform: rotate(-12deg); }
.play-card.two { right: 14px; top: 5px; transform: rotate(10deg); }
.play-card.front { left: 25px; top: 3px; transform: rotate(-1deg); z-index: 2; }
.play-card.front::after {
  content: "T";
  display: grid;
  place-items: center;
  color: #b54845;
  background: transparent;
  font-family: Georgia, serif;
  font-size: 48px;
  font-weight: 700;
}
.brand-title { margin: 0; font: 700 clamp(48px, 15vw, 76px)/.95 Georgia, "Times New Roman", serif; letter-spacing: -.05em; }
.brand-subtitle { margin: 0; color: var(--muted); font-size: 17px; }
.home-actions { width: min(100%, 360px); display: grid; gap: 12px; margin-top: 38px; }

.btn {
  border: 0;
  border-radius: 18px;
  min-height: 56px;
  padding: 14px 20px;
  font-weight: 750;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #1b2d28; box-shadow: 0 12px 34px rgba(232,198,106,.18); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--surface-strong); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); min-height: 44px; }
.btn-danger { background: rgba(229,111,101,.18); color: #ffd7d3; border: 1px solid rgba(229,111,101,.3); }
.btn-small { min-height: 42px; border-radius: 14px; padding: 9px 14px; }
.btn[disabled] { opacity: .45; cursor: default; }

.home-admin { margin-top: 16px; font-size: 14px; }
.install-note { margin-top: 26px; color: var(--muted); font-size: 13px; line-height: 1.45; max-width: 360px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 26px; }
.wordmark { display: flex; align-items: center; gap: 11px; font: 700 26px/1 Georgia, serif; }
.mini-mark { width: 35px; height: 43px; border-radius: 8px; background: #fffaf0; position: relative; transform: rotate(-4deg); box-shadow: 0 8px 20px rgba(0,0,0,.18); }
.mini-mark::after { content: "T"; position: absolute; inset: 0; display: grid; place-items: center; color: #b54845; font: 700 23px Georgia, serif; }
.icon-btn { width: 46px; height: 46px; border-radius: 15px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; }

.hero-panel, .panel {
  background: linear-gradient(160deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.hero-panel { padding: 25px; }
.hero-panel h1 { margin: 0 0 8px; font-size: 31px; }
.hero-panel p { margin: 0; color: var(--muted); line-height: 1.5; }
.dashboard-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0 26px; }
.action-card { min-height: 138px; padding: 19px; border-radius: 21px; background: var(--surface); border: 1px solid var(--line); text-align: left; cursor: pointer; }
.action-card strong { display: block; font-size: 19px; margin-top: 13px; }
.action-card span { color: var(--muted); font-size: 14px; display: block; margin-top: 5px; line-height: 1.35; }
.action-icon { font-size: 27px; }
.section-title { margin: 0 0 12px; font-size: 17px; }
.game-list { display: grid; gap: 10px; }
.game-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; padding: 15px 16px; background: rgba(0,0,0,.14); border: 1px solid var(--line); border-radius: 17px; }
.game-row strong { display: block; }
.game-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.status-pill { padding: 7px 10px; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-pill.active { color: #bdf4d3; background: rgba(103,199,146,.15); }
.status-pill.waiting { color: #ffe8a6; background: rgba(232,198,106,.14); }
.status-pill.finished { color: #c8d2ce; }
.empty-state { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 18px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; background: rgba(0,0,0,.58); backdrop-filter: blur(8px); }
.sheet { width: min(100%, 620px); margin: 0 auto; background: #0d332b; border: 1px solid var(--line); border-radius: 30px 30px 0 0; padding: 24px 20px calc(24px + var(--safe-bottom)); box-shadow: 0 -20px 70px rgba(0,0,0,.35); }
.sheet h2 { margin: 0 0 8px; font-size: 26px; }
.sheet .lead { margin: 0 0 22px; color: var(--muted); }
.field { display: grid; gap: 8px; margin-bottom: 15px; text-align: left; }
.field label { color: var(--muted); font-size: 13px; font-weight: 700; }
.field input { width: 100%; min-height: 54px; border: 1px solid var(--line); border-radius: 16px; background: rgba(0,0,0,.18); color: var(--text); padding: 0 16px; font-size: 17px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; margin-top: 20px; }

.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 25px 0; }
.pin-dot { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45); }
.pin-dot.filled { background: var(--accent); border-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { min-height: 62px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); font-size: 24px; cursor: pointer; }
.key.action { color: var(--muted); font-size: 16px; }
.pin-error { min-height: 22px; color: #ffb9b4; font-size: 14px; margin-bottom: 10px; }

.invite-card { padding: 18px; border-radius: 18px; background: rgba(0,0,0,.18); border: 1px solid var(--line); margin-top: 18px; }
.invite-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.invite-url { overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; }
.invite-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 13px; }

.game-screen { min-height: calc(100dvh - 36px - var(--safe-top) - var(--safe-bottom)); }
.game-header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.player-chip { min-width: 0; padding: 12px; background: rgba(0,0,0,.16); border: 1px solid var(--line); border-radius: 17px; }
.player-chip.right { text-align: right; }
.player-name { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 800; }
.player-role { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.vs { color: var(--accent); font: italic 700 18px Georgia, serif; }
.table-zone { flex: 1; display: grid; place-items: center; padding: 24px 0; }
.table-inner { width: 100%; text-align: center; }
.game-status { display: inline-flex; align-items: center; gap: 9px; padding: 10px 14px; background: rgba(0,0,0,.18); border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(232,198,106,.6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px rgba(232,198,106,0); } 100% { box-shadow: 0 0 0 0 rgba(232,198,106,0); } }
.deck-placeholder { position: relative; width: 146px; height: 196px; margin: 38px auto 30px; }
.deck-placeholder .play-card { width: 126px; height: 176px; border-radius: 16px; }
.deck-placeholder .play-card.one { left: 1px; top: 11px; transform: rotate(-5deg); }
.deck-placeholder .play-card.two { right: 1px; top: 6px; transform: rotate(5deg); }
.deck-placeholder .play-card.front { left: 10px; top: 0; transform: rotate(0); }
.deck-placeholder .play-card.front::after { font-size: 70px; }
.game-message { max-width: 420px; margin: 0 auto; color: var(--muted); line-height: 1.55; }
.game-footer { display: grid; gap: 10px; }
.waiting-person { font-size: 20px; font-weight: 800; margin: 14px 0 5px; }
.joined-ok { color: #bdf4d3; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(22px + var(--safe-bottom)); transform: translate(-50%, 30px); opacity: 0; pointer-events: none; background: #fffaf0; color: #14372f; padding: 12px 17px; border-radius: 14px; box-shadow: var(--shadow); font-weight: 750; transition: opacity .2s ease, transform .2s ease; text-align: center; max-width: calc(100% - 36px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.error-box { padding: 15px; border-radius: 16px; background: rgba(229,111,101,.16); color: #ffd7d3; border: 1px solid rgba(229,111,101,.3); margin-bottom: 15px; }
.loading { min-height: 100dvh; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: 30px; padding-bottom: 24px; }
}
@media (max-width: 380px) {
  .dashboard-actions { grid-template-columns: 1fr; }
  .game-header { gap: 6px; }
  .player-chip { padding: 10px 8px; }
}
