/* scorist.css — mobile-first stylesheet for Scorist
   Design principles:
   - Mobile-first (the app lives on smartphones around a table)
   - System font stack — no web font download needed
   - CSS custom properties for easy theming
   - Minimal animations (respects prefers-reduced-motion)
*/

/* ---------------------------------------------------------------------------
   Custom properties (design tokens)
   --------------------------------------------------------------------------- */
:root {
  --c-bg:         #ffffff;
  --c-bg-2:       #f5f5f4;
  --c-bg-3:       #e8e7e4;
  --c-border:     #d6d5d1;
  --c-text:       #1a1a18;
  --c-text-2:     #5c5c58;
  --c-text-3:     #9c9b96;

  --c-green:      #1d9e75;
  --c-green-bg:   #e1f5ee;
  --c-green-text: #085041;

  --c-amber:      #ba7517;
  --c-amber-bg:   #faeeda;
  --c-amber-text: #633806;

  --c-red:        #a32d2d;
  --c-red-bg:     #fcebeb;
  --c-red-text:   #791f1f;

  --c-blue:       #185fa5;
  --c-blue-bg:    #e6f1fb;
  --c-blue-text:  #0c447c;

  --c-purple-bg:  #eeedfe;
  --c-purple-text:#3c3489;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.07);
}

/* ---------------------------------------------------------------------------
   Reset & base
   --------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               Helvetica, Arial, sans-serif;
  background: var(--c-bg-2);
  color: var(--c-text);
  line-height: 1.5;
  min-height: 100dvh;
}

/* ---------------------------------------------------------------------------
   Layout shell
   --------------------------------------------------------------------------- */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------------------------------------------------------------------------
   Typography
   --------------------------------------------------------------------------- */
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; color: var(--c-text-2); text-transform: uppercase; letter-spacing: .05em; }

p  { color: var(--c-text-2); font-size: 14px; }

/* ---------------------------------------------------------------------------
   Cards & sections
   --------------------------------------------------------------------------- */
.card {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.section { display: flex; flex-direction: column; gap: 10px; }

/* ---------------------------------------------------------------------------
   Form elements
   --------------------------------------------------------------------------- */
label { font-size: 13px; color: var(--c-text-2); display: block; margin-bottom: 4px; }

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--c-bg);
  color: var(--c-text);
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--c-blue); }

/* Segmented control (replaces radio buttons) */
.seg-control {
  display: flex;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg-control button {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: var(--c-bg-2);
  color: var(--c-text-2);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-control button:not(:last-child) { border-right: 1px solid var(--c-border); }
.seg-control button.active {
  background: var(--c-text);
  color: var(--c-bg);
}

/* Chip row (quick-select buttons) */
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 14px;
  border: 1px solid var(--c-border);
  border-radius: 20px;
  font-size: 13px;
  background: var(--c-bg-2);
  color: var(--c-text-2);
  cursor: pointer;
}
.chip.active {
  background: var(--c-text);
  color: var(--c-bg);
  border-color: var(--c-text);
}

/* Toggle switch */
.toggle-wrap { display: flex; align-items: center; justify-content: space-between; }
.toggle {
  position: relative;
  width: 36px; height: 20px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--c-border);
  border-radius: 20px;
  cursor: pointer;
  transition: background .2s;
}
.toggle input:checked + .toggle-track { background: var(--c-green); }
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform .2s;
}
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */
.btn {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-align: center;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary   { background: var(--c-text);   color: var(--c-bg); }
.btn-secondary { background: var(--c-bg-2);   color: var(--c-text); border: 1px solid var(--c-border); }
.btn-success   { background: var(--c-green);  color: white; }
.btn-danger    { background: var(--c-red);    color: white; }

/* Small inline buttons */
.btn-sm {
  display: inline-block;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-sm-accept { background: var(--c-green-bg); color: var(--c-green-text); border-color: var(--c-green); }
.btn-sm-reject { background: var(--c-red-bg);   color: var(--c-red-text);   border-color: var(--c-red); }

/* ---------------------------------------------------------------------------
   Badges & pills
   --------------------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-host   { background: var(--c-blue-bg);   color: var(--c-blue-text); }
.badge-ghost  { background: var(--c-bg-3);       color: var(--c-text-2); }
.badge-ok     { background: var(--c-green-bg);   color: var(--c-green-text); }
.badge-warn   { background: var(--c-amber-bg);   color: var(--c-amber-text); }

/* ---------------------------------------------------------------------------
   Player rows
   --------------------------------------------------------------------------- */
.player-list { display: flex; flex-direction: column; }

.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--c-bg-2);
}
.player-row:last-child { border-bottom: none; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--c-blue-bg);
  color: var(--c-blue-text);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.player-name { flex: 1; font-size: 14px; font-weight: 500; }
.player-score { font-size: 18px; font-weight: 700; }
.player-score.empty { color: var(--c-text-3); font-weight: 400; }
.score-negative { color: var(--c-red-text); }

/* Rank badge */
.rank-badge {
  width: 24px;
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text-3);
  text-align: center;
  flex-shrink: 0;
}
.rank-badge.rank-1 { color: #b7860b; } /* gold   */
.rank-badge.rank-2 { color: #7a7a7a; } /* silver */
.rank-badge.rank-3 { color: #8b5a2b; } /* bronze */

/* Current player highlight */
.player-row.is-me { background: var(--c-bg-2); border-radius: var(--radius-sm); padding: 10px 8px; margin: 0 -8px; }

/* ---------------------------------------------------------------------------
   Score input
   --------------------------------------------------------------------------- */
.score-input-wrap {
  background: var(--c-bg-2);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.score-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sign-toggle {
  display: flex;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.sign-btn {
  padding: 8px 14px;
  font-size: 16px;
  font-weight: 700;
  background: var(--c-bg-2);
  color: var(--c-text-2);
  border: none;
  cursor: pointer;
}
.sign-btn.active {
  background: var(--c-text);
  color: var(--c-bg);
}
.sign-btn:not(:last-child) { border-right: 1px solid var(--c-border); }

input.score-field {
  width: 96px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
}

/* ---------------------------------------------------------------------------
   Notification banner (pending join during game)
   --------------------------------------------------------------------------- */
.notif-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--c-amber-bg);
  border: 1px solid var(--c-amber);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--c-amber-text);
  cursor: pointer;
}
.notif-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--c-amber);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Code display (lobby)
   --------------------------------------------------------------------------- */
.room-code {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: .18em;
  font-family: ui-monospace, 'Cascadia Code', monospace;
  text-align: center;
  color: var(--c-text);
}

.share-row {
  display: flex;
  gap: 6px;
}
.share-btn {
  flex: 1;
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-bg-2);
  color: var(--c-text-2);
  cursor: pointer;
  text-align: center;
}

/* ---------------------------------------------------------------------------
   Settings summary card (shown in lobby to all players)
   --------------------------------------------------------------------------- */
.settings-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  font-size: 13px;
}
.settings-summary dt { color: var(--c-text-2); }
.settings-summary dd { font-weight: 600; text-align: right; }

/* ---------------------------------------------------------------------------
   Scoreboard table (round overview)
   --------------------------------------------------------------------------- */
.scoreboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.scoreboard-table th {
  color: var(--c-text-3);
  font-weight: 500;
  padding: 4px 6px;
  border-bottom: 1px solid var(--c-border);
  text-align: right;
}
.scoreboard-table th:first-child { text-align: left; }
.scoreboard-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--c-bg-2);
  text-align: right;
}
.scoreboard-table td:first-child { text-align: left; color: var(--c-text-2); }
.scoreboard-table tr:last-child td { border-bottom: none; }
.scoreboard-table .total-col { font-weight: 700; }
.scoreboard-table .empty-cell { color: var(--c-text-3); }

/* ---------------------------------------------------------------------------
   Tab bar
   --------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--c-bg-2);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.tab-btn {
  flex: 1;
  padding: 7px;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  color: var(--c-text-2);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab-btn.active { background: var(--c-bg); color: var(--c-text); box-shadow: var(--shadow-sm); }

/* ---------------------------------------------------------------------------
   Connection status bar
   --------------------------------------------------------------------------- */
.conn-bar {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
}
.conn-bar.reconnecting { background: var(--c-amber-bg); color: var(--c-amber-text); }
.conn-bar.disconnected { background: var(--c-red-bg);   color: var(--c-red-text); }

/* ---------------------------------------------------------------------------
   Toast notification (brief feedback messages)
   --------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 420px;
}
.toast {
  background: var(--c-text);
  color: var(--c-bg);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  width: 100%;
  text-align: center;
  animation: toast-in .2s ease;
}
.toast.error { background: var(--c-red); }
.toast.warn  { background: var(--c-amber); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------------
   QR overlay
   --------------------------------------------------------------------------- */
.overlay-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.overlay-sheet {
  background: var(--c-bg);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-sm);
  padding: 20px 16px 32px;
  width: 100%;
  max-width: 480px;
}

/* ---------------------------------------------------------------------------
   Animations & transitions
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  .player-row { transition: background .2s; }
  .fade-enter-active, .fade-leave-active { transition: opacity .2s; }
  .fade-enter-from, .fade-leave-to { opacity: 0; }
}

/* ---------------------------------------------------------------------------
   Utilities
   --------------------------------------------------------------------------- */
.divider { height: 1px; background: var(--c-border); }
.text-muted  { color: var(--c-text-2); font-size: 13px; }
.text-hint   { color: var(--c-text-3); font-size: 12px; }
.text-center { text-align: center; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.gap-8  { gap: 8px; }
.flex   { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
