:root {
  --bg: #f2f4f8;
  --bg-gradient: radial-gradient(circle at 50% 0%, #ffffff 0%, #eef1f7 55%, #e4e8f1 100%);
  --surface: #ffffff;
  --surface-alt: #f7f8fb;
  --border: #dde1ea;
  --text: #1c2230;
  --text-muted: #6b7280;
  --accent: #6d5bff;
  --accent-hover: #5a49e6;
  --accent-soft: rgba(109, 91, 255, 0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --card-back: #3d4a6b;
  --card-back-2: #2b3555;
  --shadow: 0 10px 30px rgba(20, 25, 40, 0.12);
  --shadow-sm: 0 2px 8px rgba(20, 25, 40, 0.08);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #12141c;
  --bg-gradient: radial-gradient(circle at 50% 0%, #1c2030 0%, #14161f 55%, #0d0f16 100%);
  --surface: #1b1e2a;
  --surface-alt: #20232f;
  --border: #2c3040;
  --text: #eef0f6;
  --text-muted: #9aa0b4;
  --accent: #8a7bff;
  --accent-hover: #9c8fff;
  --accent-soft: rgba(138, 123, 255, 0.18);
  --success: #34d399;
  --danger: #f87171;
  --card-back: #4b5a86;
  --card-back-2: #313d5f;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  transition: background-color .2s ease, color .2s ease;
}

/* ---------- Header ---------- */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.2px;
}

.brand-mark {
  font-size: 1.4rem;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, background-color .2s ease;
}

.icon-btn:hover {
  transform: translateY(-1px) scale(1.04);
  background: var(--surface-alt);
}

/* ---------- Main / Table ---------- */
.app-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 16px;
}

.table-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 900px;
  height: 100%;
}

.table-area {
  position: relative;
  width: min(88vw, 700px);
  aspect-ratio: 16 / 10;
  max-height: 100%;
  margin: 46px 0 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.seats {
  position: absolute;
  inset: 0;
}

.center-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: min(72%, 380px);
  min-height: 44%;
  padding: 22px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.status-text {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
}

.stats {
  display: flex;
  align-items: stretch;
  gap: 24px;
  animation: pop-in .25s ease;
}

.stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stats .stat + .stat {
  border-left: 1px solid var(--border);
  padding-left: 24px;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Reveal animation ---------- */
.reveal-circle {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 100px;
  height: 100px;
  z-index: 6;
  pointer-events: none;
}

.reveal-circle svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.reveal-circle-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.reveal-circle-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 264;
  stroke-dashoffset: 264;
}

.reveal-circle.running .reveal-circle-progress {
  animation: circle-fill 1s linear forwards;
}

@keyframes circle-fill {
  to { stroke-dashoffset: 0; }
}

/* ---------- Seats around the table ---------- */
.seat {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transform: translate(-50%, -50%);
  animation: seat-in .25s ease;
}

@keyframes seat-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.seat-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat.is-you .seat-name {
  border-color: var(--accent);
  color: var(--accent);
}

.seat-card {
  width: 46px;
  height: 64px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(0, 0, 0, 0.08);
  transition: transform .25s ease;
  perspective: 400px;
}

.seat-card.empty {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 1.3rem;
}

.seat-card.waiting {
  background: repeating-linear-gradient(135deg, var(--card-back), var(--card-back) 6px, var(--card-back-2) 6px, var(--card-back-2) 12px);
  color: transparent;
}

.seat-card.voted {
  background: linear-gradient(160deg, var(--card-back), var(--card-back-2));
  color: rgba(255, 255, 255, 0.85);
  font-size: 1.3rem;
  animation: card-bump .3s ease;
}

@keyframes card-bump {
  0% { transform: translateY(4px) scale(0.9); }
  60% { transform: translateY(-3px) scale(1.03); }
  100% { transform: translateY(0) scale(1); }
}

.seat-card.revealed {
  background: var(--surface);
  color: var(--text);
  animation: flip .4s ease;
}

@keyframes flip {
  0% { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

/* ---------- Controls on the table ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, background-color .2s ease, box-shadow .2s ease;
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

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

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

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ---------- Hand of cards ---------- */
.hand-wrap {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 6px 16px 14px;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 900px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.hand-card {
  width: 46px;
  height: 64px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}

.hand-card:hover {
  transform: translateY(-6px);
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.hand-card.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-10px);
}

.hand-card:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

/* ---------- Join modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 20, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  z-index: 50;
  padding: max(16px, 10vh) 16px 16px;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: 18px;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  text-align: center;
}

.modal h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

.modal p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

#join-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#name-input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1rem;
}

#name-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.modal .join-error {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.85rem;
  margin: -4px 0 0;
  text-align: left;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .seat-card {
    width: 38px;
    height: 54px;
    font-size: 0.9rem;
  }

  .seat-name {
    font-size: 0.7rem;
    max-width: 80px;
  }

  .hand-card {
    width: 38px;
    height: 54px;
    font-size: 0.85rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }

  .center-panel {
    padding: 16px;
  }
}

/* Short viewports (typical laptop windows with browser chrome): shrink
   vertical breathing room so everything fits without a scrollbar. */
@media (max-height: 720px) {
  .app-header {
    padding: 6px 24px;
  }

  .table-area {
    margin: 30px 0 34px;
  }

  .center-panel {
    padding: 14px 22px;
    gap: 10px;
  }

  .stat-value {
    font-size: 1.7rem;
  }

  .hand-wrap {
    padding: 4px 16px 10px;
  }

  .hand {
    padding: 8px;
    gap: 6px;
  }

  .hand-card {
    width: 40px;
    height: 56px;
  }

  .seat-card {
    width: 40px;
    height: 56px;
  }
}

/* Phones are tall and narrow - a landscape-shaped table wastes most of the
   screen height and crowds seats sideways. Flip it to portrait so seats
   spread out using the space that's actually available. Placed after the
   max-height query so its margin wins on phones that match both. */
@media (max-width: 480px) {
  .table-area {
    width: min(78vw, 380px);
    aspect-ratio: 10 / 16;
    margin: 24px 0 28px;
  }
}
