/* ════════════════════════════════════════════
   AgilePointing – Stylesheet
   ════════════════════════════════════════════ */

/* ─── Custom Properties ─────────────────────── */
:root {
  --primary:        #6366f1;
  --primary-hover:  #4f46e5;
  --primary-light:  #eef2ff;
  --primary-border: #c7d2fe;
  --success:        #22c55e;
  --success-light:  #dcfce7;
  --warning:        #f59e0b;
  --warning-light:  #fef3c7;
  --error:          #ef4444;
  --error-light:    #fee2e2;

  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --border:         #e2e8f0;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --text-faint:     #94a3b8;

  --radius-sm:      8px;
  --radius:         12px;
  --radius-lg:      16px;
  --radius-xl:      24px;
  --shadow-sm:      0 1px 2px rgba(0,0,0,.06);
  --shadow:         0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:      0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:      0 10px 15px rgba(0,0,0,.10), 0 4px 6px rgba(0,0,0,.05);
  --shadow-card:    0 2px 8px rgba(99,102,241,.12), 0 1px 2px rgba(0,0,0,.08);
}

/* ─── Reset ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── Views ──────────────────────────────────── */
.view {
  display: none;
  min-height: 100vh;
}
.view.active { display: flex; }

/* ─── WELCOME VIEW ──────────────────────────── */
#welcome-view {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.welcome-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.welcome-logo {
  text-align: center;
  padding-bottom: 0.5rem;
}
.logo-emoji { font-size: 3rem; display: block; margin-bottom: .5rem; }
.logo-image-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin: 0 auto .5rem;
}
.logo-bug { font-size: 2rem; display: inline-block; }
.logo-image { height: 4rem; width: auto; display: block; }
.welcome-logo h1 {
  font-size: 1.875rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
}
.tagline {
  color: var(--text-muted);
  font-size: .875rem;
  margin-top: .25rem;
}

/* ─── Form ───────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: .375rem;
}
label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
input[type="text"] {
  width: 100%;
  padding: .6875rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
input[type="text"]::placeholder { color: var(--text-faint); }
input[type="password"] {
  width: 100%;
  padding: .6875rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
input[type="password"]::placeholder { color: var(--text-faint); }

/* ─── Text utility ──────────────────────────── */
.text-muted {
  color: var(--text-muted);
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
}

/* ─── Hidden utility ────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--text-faint);
  font-size: .8125rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Join Row ───────────────────────────────── */
.join-row {
  display: flex;
  gap: .5rem;
}
.join-row input { flex: 1; }
.join-row .btn { flex-shrink: 0; white-space: nowrap; }

/* ─── Error message ─────────────────────────── */
.error-msg {
  color: var(--error);
  font-size: .875rem;
  background: var(--error-light);
  padding: .625rem .875rem;
  border-radius: var(--radius-sm);
  border: 1px solid #fca5a5;
}

/* ─── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  padding: .6875rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .9375rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: background .15s, transform .1s, box-shadow .15s;
  text-decoration: none;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}
.btn-full { width: 100%; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(99,102,241,.3);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 8px rgba(99,102,241,.35);
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--primary-border);
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--text-muted);
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: .375rem;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); background: var(--bg); }

/* ─── ROOM VIEW ──────────────────────────────── */
#room-view {
  flex-direction: column;
  min-height: 100vh;
}

/* ─── Room Header ────────────────────────────── */
.room-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .875rem 1.5rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}
.header-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.room-header-center {
  display: flex;
  justify-content: center;
}
.room-header-image {
  height: 4rem;
  width: auto;
}
.logo-emoji-sm { font-size: 1.375rem; }
.brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}
.room-badge {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--primary-light);
  border: 1.5px solid var(--primary-border);
  border-radius: 9999px;
  padding: .3125rem .75rem .3125rem .875rem;
}
.room-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.room-code {
  font-size: .9375rem;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  color: var(--primary-hover);
  letter-spacing: .1em;
}

/* ─── Room Main ──────────────────────────────── */
.room-main {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.room-branding-center {
  display: flex;
  justify-content: center;
}
.room-branding-image {
  height: 5rem;
  width: auto;
}

/* ─── Sections ───────────────────────────────── */
.section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.375rem 1.5rem;
  box-shadow: var(--shadow);
}
.section-title {
  font-size: .875rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 1rem;
}

/* ─── Voting Cards Grid ──────────────────────── */
.cards-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  justify-content: center;
}

/* ─── Voting Card ────────────────────────────── */
.vote-card {
  width: 68px;
  height: 96px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s, transform .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
  user-select: none;
  position: relative;
  overflow: hidden;
}
.vote-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(99,102,241,.06));
  pointer-events: none;
}
.vote-card:hover:not(.selected):not(.disabled) {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: var(--shadow-card);
}
.vote-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-hover);
  transform: translateY(-6px);
  box-shadow: 0 6px 16px rgba(99,102,241,.25);
}
.vote-card.disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

/* ─── Results Section ────────────────────────── */
.results-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  background: var(--primary-light);
  border: 1.5px solid var(--primary-border);
  border-radius: var(--radius-sm);
  padding: .75rem 1.25rem;
  min-width: 90px;
  text-align: center;
}
.stat-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--primary);
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary-hover);
}
.consensus-badge {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  background: var(--success-light);
  border: 1.5px solid #86efac;
  color: #15803d;
  font-size: .875rem;
  font-weight: 600;
  padding: .5rem 1rem;
  border-radius: 9999px;
  align-self: center;
}

/* ─── Participants ───────────────────────────── */
.participants-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.participants-header .section-title { margin-bottom: 0; }
.vote-badge {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 9999px;
  padding: .1875rem .625rem;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-muted);
}
.participants-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.participant {
  display: flex;
  align-items: center;
  gap: .875rem;
  padding: .625rem .75rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1.5px solid var(--border);
  transition: border-color .15s;
}
.participant.is-me {
  background: var(--primary-light);
  border-color: var(--primary-border);
}

/* ─── Avatar Picker ──────────────────────────── */
.avatar-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: .375rem;
}
.avatar-option {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s, transform .1s;
  line-height: 1;
}
.avatar-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: scale(1.1);
}
.avatar-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}

/* ─── Participant Avatar ─────────────────────── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: .875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s, color .2s;
  text-transform: uppercase;
}
.avatar.voted {
  background: var(--primary);
  color: #fff;
}
.avatar.avatar-emoji {
  background: var(--bg);
  border: 2px solid var(--border);
  font-size: 1.125rem;
  color: inherit;
}
.avatar.avatar-emoji.voted {
  background: var(--primary-light);
  border-color: var(--primary);
  color: inherit;
}

.participant-name {
  flex: 1;
  font-size: .9375rem;
  font-weight: 500;
  color: var(--text);
}
.you-tag {
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 9999px;
  padding: .125rem .5rem;
  margin-left: .375rem;
}

/* ─── Participant Vote Indicator ─────────────── */
.participant-vote-chip {
  min-width: 44px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid transparent;
}
.participant-vote-chip.state-not-voted {
  background: transparent;
  color: var(--text-faint);
  border-color: var(--border);
  font-size: 1.125rem;
}
.participant-vote-chip.state-voted-hidden {
  background: var(--primary);
  color: transparent;
  border-color: var(--primary-hover);
  font-size: .625rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.participant-vote-chip.state-voted-hidden::after {
  content: '✓';
  color: #fff;
  font-size: 1rem;
}
.participant-vote-chip.state-revealed {
  background: var(--surface);
  color: var(--primary-hover);
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(99,102,241,.2);
  min-width: 52px;
  font-size: 1.125rem;
}

/* Vote color coding (highest consensus = green, multiple = warning, single = neutral) */
.participant-vote-chip.state-revealed.vote-color-highest {
  background: var(--success-light);
  color: #166534;
  border-color: var(--success);
  box-shadow: 0 2px 6px rgba(34,197,94,.25);
}

.participant-vote-chip.state-revealed.vote-color-high {
  background: var(--warning-light);
  color: #92400e;
  border-color: var(--warning);
  box-shadow: 0 2px 6px rgba(245,158,11,.25);
}

.participant-vote-chip.state-revealed.vote-color-normal {
  background: var(--surface);
  color: var(--primary-hover);
  border-color: var(--border);
  box-shadow: 0 2px 6px rgba(99,102,241,.2);
}

/* ─── Room Footer ────────────────────────────── */
.room-footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  gap: .75rem;
  justify-content: center;
  box-shadow: 0 -4px 12px rgba(0,0,0,.07);
}
.room-footer .btn { min-width: 160px; }

/* ─── Toast ──────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: .625rem 1.25rem;
  border-radius: 9999px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  white-space: nowrap;
  animation: fade-up .2s ease;
}

/* ─── Utilities ──────────────────────────────── */
.hidden { display: none !important; }

/* ─── Animations ─────────────────────────────── */
@keyframes fade-up {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(.85); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes reveal-card {
  0% { opacity: 0; transform: rotateX(90deg) translateY(10px); }
  40% { opacity: 1; transform: rotateX(-10deg) translateY(-4px); }
  100% { opacity: 1; transform: rotateX(0) translateY(0); }
}

.vote-card.revealed {
  animation: reveal-card .35s ease-out;
  border-color: var(--success);
  box-shadow: 0 8px 20px rgba(34,197,94,.25);
}
.participant-vote-chip.state-revealed,
.participant-vote-chip.state-revealed.vote-color-highest,
.participant-vote-chip.state-revealed.vote-color-high,
.participant-vote-chip.state-revealed.vote-color-normal {
  animation: pop-in .25s ease;
}

/* ─── Sound Toggle Button ────────────────────── */
.sound-toggle {
  position: fixed;
  top: .75rem;
  right: 3.5rem;
  z-index: 200;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: .5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: background .15s, color .15s, border-color .15s;
}
.sound-toggle:hover { color: var(--text); background: var(--bg); }

/* ─── Theme Toggle Button ────────────────────── */
.theme-toggle {
  position: fixed;
  top: .75rem;
  right: .75rem;
  z-index: 200;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: .5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: background .15s, color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--text); background: var(--bg); }

/* ─── Dark Theme ─────────────────────────────── */
:root[data-theme="dark"] {
  --primary-light:  #1e1b4b;
  --primary-border: #4338ca;
  --success-light:  #052e16;
  --warning-light:  #451a03;
  --error-light:    #450a0a;
  --bg:             #0f172a;
  --surface:        #1e293b;
  --border:         #334155;
  --text:           #f1f5f9;
  --text-muted:     #94a3b8;
  --text-faint:     #475569;
}
:root[data-theme="dark"] #welcome-view {
  background: linear-gradient(135deg, #312e81 0%, #4c1d95 100%);
}
:root[data-theme="dark"] .toast {
  background: #e2e8f0;
  color: #1e293b;
}
:root[data-theme="dark"] .consensus-badge { color: #4ade80; }
:root[data-theme="dark"] .participant-vote-chip.state-revealed.vote-color-highest { color: #4ade80; }
:root[data-theme="dark"] .participant-vote-chip.state-revealed.vote-color-high { color: #fcd34d; }
:root[data-theme="dark"] .error-msg { border-color: var(--error); }
:root[data-theme="dark"] .logo-image,
:root[data-theme="dark"] .room-header-image { filter: invert(1); }

/* ─── Responsive ─────────────────────────────── */

/* Ensure room badge never sits under the fixed sound+theme toggles */
.room-header { padding-right: 6.5rem; }

/* Small screens: phones and small tablets (≤ 640px) */
@media (max-width: 640px) {
  /* Hide header branding image — logo still visible in welcome card */
  .room-header-center { display: none; }

  /* Stack footer buttons vertically for easier thumb access */
  .room-footer {
    flex-direction: column;
    padding: .875rem 1rem;
    gap: .5rem;
  }
  .room-footer .btn {
    width: 100%;
    min-width: unset;
  }
}

/* Small phones (≤ 480px) */
@media (max-width: 480px) {
  .welcome-card { padding: 2rem 1.25rem; }
  .room-header { padding: .75rem 1rem; padding-right: 6.5rem; }
  .room-main { padding: 1rem; gap: 1rem; }
  .section { padding: 1rem; }
  .vote-card { width: 58px; height: 82px; font-size: 1.1rem; }
  .cards-grid { gap: .5rem; }
  .stat-value { font-size: 1.4rem; }
}
