:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel2: #20242e;
  --border: #2a2e3a;
  --accent: #7c6cff;
  --accent2: #ff6ca0;
  --text: #eef0f6;
  --dim: #8a8f9e;
  --good: #4ade80;
  --danger: #ef5a5a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
}

#app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 14px 14px 0;
  gap: 10px;
}

h1, h2, h3 { margin: 0 0 4px 0; }
h1 { font-size: 1.25rem; }
h2 { font-size: 0.95rem; color: var(--text); }
p { margin: 4px 0; color: var(--dim); font-size: 0.88rem; line-height: 1.4; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
button.secondary { background: var(--panel2); border: 1px solid var(--border); color: var(--text); }
button.danger { background: var(--danger); }
button.small { padding: 5px 10px; font-size: 0.75rem; border-radius: 6px; }
button:disabled { opacity: 0.4; cursor: default; }

a.button {
  display: inline-block;
  text-align: center;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  box-sizing: border-box;
}
.account-line { font-size: 0.8rem; }
.account-line a { color: var(--text); text-decoration: underline; }

input, select {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.9rem;
  width: 100%;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}

.lobby-code {
  font-size: 1.8rem;
  letter-spacing: 0.18em;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---- phase status bar: pulsing pill + progress-bar timer ---- */
.phasebar { display: flex; flex-direction: column; gap: 6px; }
.phasepill {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 20px;
  padding: 4px 11px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text);
}
.phasepill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.timerbar { height: 4px; background: var(--border); border-radius: 3px; overflow: hidden; }
.timerbar .fill { height: 100%; background: var(--accent2); transition: width 0.3s linear; }

/* ---- Town View / pick grids ---- */
.branch-label { font-size: 0.72rem; color: var(--dim); font-weight: 600; margin: 8px 0 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.branch-label .dimmed { color: #555b6b; font-weight: 400; font-style: italic; text-transform: none; letter-spacing: 0; }
.or-divider { text-align: center; font-size: 0.65rem; font-weight: 800; color: var(--accent2); letter-spacing: 0.1em; margin: 10px 0 2px; }

.town-view, .pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.town-view.one-col, .pick-grid.one-col { grid-template-columns: 1fr; }

.tile {
  position: relative;
  background: var(--panel2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s;
}
.tile:active { transform: scale(0.97); }
.tile.locked { opacity: 0.35; pointer-events: none; }
.tile.selected { border-color: var(--accent); background: rgba(124, 108, 255, 0.18); }
.tile.center { background: linear-gradient(160deg, #2a2440, #181622); border-color: #3a3360; }
.tile .avatar { font-size: 1.3rem; line-height: 1; }
.tile .name { font-weight: 600; font-size: 0.8rem; margin-top: 3px; }
.tile .sub { font-size: 0.65rem; color: var(--dim); margin-top: 1px; }
.tile .slot-badge {
  position: absolute; top: -7px; right: -7px;
  background: var(--accent); color: white; border-radius: 10px;
  padding: 1px 6px; font-size: 0.6rem; font-weight: 800;
}
.tile .badge {
  display: inline-block; margin-top: 4px; font-size: 0.6rem; padding: 1px 6px;
  border-radius: 6px; background: #3a3f55; color: var(--dim);
}
.tile .badge.away { background: #5a4a22; color: #e0c070; }
.tile .badge.dead { background: #5a2222; color: #e08080; }
.tile .badge.winner { background: #1f4a30; color: var(--good); }
.tile .badge.left { background: #333; color: var(--dim); }
.tile .role { font-size: 0.65rem; color: var(--accent2); margin-top: 2px; }

.live-note {
  font-size: 0.68rem; color: var(--dim); text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 5px; padding: 6px 0 0;
}
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); animation: pulse 1s infinite; }

/* ---- result-card history: bottom sheet + swipeable carousel ---- */
.history-handle {
  flex-shrink: 0; text-align: center; padding: 9px 0; font-size: 0.7rem; color: var(--dim);
  cursor: pointer; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  margin-top: auto;
}
.history-handle .bump { width: 32px; height: 4px; background: var(--border); border-radius: 3px; margin: 0 auto 6px; }

.history-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 460px; margin: 0 auto;
  background: #0d0e13; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0;
  height: 0; overflow: hidden; transition: height 0.26s ease; z-index: 60;
}
.history-sheet.open { height: 62vh; }
.history-sheet .hdr { padding: 12px 16px 6px; display: flex; justify-content: space-between; align-items: center; }
.history-sheet .hdr b { font-size: 0.85rem; }
.history-sheet .hdr span { font-size: 0.72rem; color: var(--dim); cursor: pointer; }

.carousel {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px;
  padding: 4px 20px 16px; height: calc(100% - 36px); align-items: stretch;
}
.carousel::-webkit-scrollbar { display: none; }
.rcard {
  scroll-snap-align: center; flex-shrink: 0; width: 240px;
  background: linear-gradient(160deg, #232738, #15161d); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; display: flex; flex-direction: column; position: relative;
}
.rcard.newest { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(124, 108, 255, 0.3); }
.rcard .ph { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent2); font-weight: 700; }
.rcard .tx { font-size: 0.85rem; color: #cfd3e0; line-height: 1.45; flex: 1; margin-top: 6px; }
.rcard .newest-badge {
  position: absolute; top: 10px; right: 10px; background: var(--good); color: #06230f;
  font-size: 0.6rem; font-weight: 800; padding: 2px 6px; border-radius: 8px;
}
.dots { display: flex; justify-content: center; gap: 5px; padding-bottom: 6px; }
.dots .d { width: 5px; height: 5px; border-radius: 50%; background: var(--border); }
.dots .d.cur { background: var(--accent); }

.toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%) translateY(-10px);
  background: var(--accent); color: white; font-size: 0.75rem; font-weight: 700;
  padding: 7px 14px; border-radius: 20px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  z-index: 80; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.banner { text-align: center; padding: 16px 0; }
.banner.win { color: var(--good); font-size: 1.4rem; font-weight: 700; }
.banner.lose { color: var(--danger); font-size: 1.4rem; font-weight: 700; }

.footer-actions { margin-top: auto; display: flex; gap: 8px; padding-bottom: 14px; }
.error-toast { background: var(--danger); color: white; padding: 7px 11px; border-radius: 10px; font-size: 0.82rem; }
