:root {
  --bg: radial-gradient(circle at top left, #fff6e2 0%, #f2f5ff 42%, #e6f3ef 100%);
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: #ffffff;
  --text: #1a2333;
  --muted: #576075;
  --primary: #1f7a6a;
  --primary-strong: #0f5f52;
  --danger: #9f2b2b;
  --border: #c6d3dc;
  --card-back: #27496d;
}

[data-theme="dark"] {
  --bg: radial-gradient(circle at top left, #111827 0%, #1b2238 48%, #10251f 100%);
  --surface: rgba(19, 27, 37, 0.88);
  --surface-strong: #182131;
  --text: #e8edf7;
  --muted: #9ca7b8;
  --primary: #38a18b;
  --primary-strong: #27806f;
  --danger: #ef7f7f;
  --border: #3a485d;
  --card-back: #365a81;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.page {
  width: min(1200px, 95vw);
  margin: 2rem auto;
}

.home-card,
.join-card,
.message-card,
.panel,
.modal-content {
  background: var(--surface);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 8px 30px rgba(27, 50, 70, 0.12);
}

.home-card,
.join-card,
.message-card {
  max-width: 520px;
  margin: 10vh auto;
}

.session-page {
  display: grid;
  gap: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.topbar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.session-grid {
  display: grid;
  grid-template-columns: 290px 1fr 300px;
  gap: 1rem;
  min-height: 70vh;
}

.mobile-switcher {
  display: none;
}

.panel {
  min-height: 0;
}

.backlog-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1,
h2,
h3,
label,
strong {
  margin-top: 0;
}

h2 {
  margin-bottom: 0.5rem;
}

input,
textarea,
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin: 0.35rem 0 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
}

.btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  color: var(--text);
  background: #f5f8fa;
}

.btn:hover {
  background: #edf2f6;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary-strong);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-strong);
}

.btn-danger {
  background: #8f2730;
  border-color: #7a1f27;
  color: #fff;
}

.btn-danger:hover {
  background: #7a1f27;
}

.danger {
  border-color: #dca5a5;
  color: var(--danger);
}

[data-theme="dark"] .btn {
  background: #223044;
  color: var(--text);
}

[data-theme="dark"] .btn:hover {
  background: #2a3b54;
}

[data-theme="dark"] .btn-danger {
  background: #b43a45;
  border-color: #9c303a;
  color: #fff;
}

.actions-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.home-card .actions-row {
  margin-bottom: 0.9rem;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.error {
  min-height: 1em;
  color: var(--danger);
  margin: 0.25rem 0;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.table-panel {
  position: relative;
  overflow: hidden;
}

.center-title {
  text-align: center;
  margin-top: 0.3rem;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 700;
}

.center-subtitle {
  text-align: center;
  color: var(--muted);
  min-height: 1.5em;
}

.center-link {
  display: block;
  text-align: center;
  margin: 0.25rem auto 0.5rem;
  color: #005e9f;
}

.card-ring {
  position: relative;
  width: min(630px, 90%);
  aspect-ratio: 1 / 1;
  margin: 1rem auto;
  border-radius: 36% / 30%;
  border: 1px dashed #b6c2cc;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.2));
}

.player-slot {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 84px;
  text-align: center;
}

.card {
  width: 74px;
  height: 102px;
  border-radius: 12px;
  margin: 0 auto 0.35rem;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.card-empty {
  border: 2px dashed #9aa8b4;
  background: rgba(255, 255, 255, 0.4);
}

.card-submitted {
  background: repeating-linear-gradient(
    45deg,
    var(--card-back),
    var(--card-back) 10px,
    #3d6289 10px,
    #3d6289 20px
  );
  color: #fff;
}

.card-revealed {
  background: #ffffff;
  border: 2px solid #6d8296;
  color: var(--text);
}

[data-theme="dark"] .card-revealed {
  background: #f4f7fb;
  border-color: #9fb0c2;
  color: #1b2435;
}

.player-name {
  font-size: 0.8rem;
  color: var(--muted);
}

.vote-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.vote-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0;
  background: var(--surface-strong);
  cursor: pointer;
  color: var(--text);
}

.vote-btn.active {
  border-color: var(--primary-strong);
  background: #def3ee;
}

[data-theme="dark"] .vote-btn.active {
  color: #1b2435;
  background: #dff6ef;
}

.my-vote {
  color: var(--muted);
  margin-bottom: 0.7rem;
}

.vote-action-bar {
  display: block;
}

.host-pill,
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.74rem;
  background: #dff2ee;
  color: #0f5f52;
  border: 1px solid #abd7cd;
}

.pill.deferred {
  background: #f3e6d7;
  color: #8c5c14;
  border-color: #dfc29a;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 0.9rem 0;
}

.backlog-list {
  display: grid;
  gap: 0.5rem;
  max-height: none;
  height: 100%;
  min-height: 280px;
  overflow: auto;
  align-content: start;
}

.backlog-item {
  text-align: left;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem;
  cursor: pointer;
  color: var(--text);
}

.backlog-item.active {
  border-color: var(--primary-strong);
  box-shadow: inset 0 0 0 1px var(--primary-strong);
}

.backlog-item-row {
  display: flex;
  justify-content: space-between;
  gap: 0.3rem;
  align-items: center;
}

.backlog-item p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.backlog-item strong {
  color: var(--text);
}

.add-item-tile {
  border: 2px dashed var(--border);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 64px;
  margin-top: 0.2rem;
  color: var(--text);
  font-weight: 700;
}

.add-icon {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.host-settings {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  margin-bottom: 0.7rem;
}

.host-settings h4 {
  margin: 0 0 0.5rem;
}

.host-accordion summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
  margin-bottom: 0.55rem;
}

.host-accordion summary::-webkit-details-marker {
  display: none;
}

.host-accordion summary::after {
  content: "▾";
  float: right;
  color: var(--muted);
}

.host-accordion:not([open]) summary::after {
  content: "▸";
}

.host-actions {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.host-actions .btn {
  width: 100%;
}

.qa-panel {
  margin-top: 0.7rem;
}

.qa-actions {
  display: grid;
  gap: 0.45rem;
}

.qa-actions .btn {
  width: 100%;
}

.icon {
  margin-right: 0.35rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toggle-row input {
  width: auto;
  margin: 0;
}

.leave-btn {
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(10, 18, 24, 0.42);
}

.modal.open {
  display: grid;
}

.modal-content {
  width: min(440px, 92vw);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1f2f3f;
  color: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .session-grid {
    grid-template-columns: 1fr;
  }

  .card-ring {
    width: min(560px, 96%);
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 768px) {
  .session-page {
    margin: 1rem auto;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .mobile-switcher {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    position: sticky;
    top: 0.5rem;
    z-index: 4;
    padding: 0.35rem;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(8px);
  }

  .mobile-tab.active {
    border-color: var(--primary-strong);
    background: #def3ee;
  }

  [data-theme="dark"] .mobile-tab.active {
    background: #2e5a52;
  }

  .session-page.mobile-view-table #controls-panel,
  .session-page.mobile-view-table #backlog-panel {
    display: none;
  }

  .session-page.mobile-view-vote #table-panel,
  .session-page.mobile-view-vote #backlog-panel {
    display: none;
  }

  .session-page.mobile-view-backlog #table-panel,
  .session-page.mobile-view-backlog #controls-panel {
    display: none;
  }

  .controls-panel .vote-picker {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .card-ring {
    width: min(520px, 92%);
  }

  .player-slot {
    width: 70px;
  }

  .card {
    width: 62px;
    height: 88px;
    border-radius: 10px;
  }

  .controls-panel .btn {
    min-height: 48px;
    font-weight: 600;
  }

  .vote-btn {
    min-height: 48px;
    font-size: 1rem;
  }

  .vote-action-bar {
    position: sticky;
    bottom: 0;
    z-index: 3;
    padding: 0.6rem 0 calc(0.6rem + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--surface) 72%, rgba(255, 255, 255, 0));
    margin-top: 0.35rem;
  }

  [data-theme="dark"] .vote-action-bar {
    background: linear-gradient(to top, var(--surface) 72%, rgba(24, 33, 49, 0));
  }

  .vote-action-bar .my-vote {
    margin-bottom: 0.45rem;
  }
}
