/* ============================================================
   Планировочный дурак — Styles
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #263045;
  --border:    #334155;
  --text:      #e2e8f0;
  --muted:     #94a3b8;
  --accent:    #6366f1;
  --accent-h:  #4f46e5;
  --accent-l:  #818cf8;
  --success:   #22c55e;
  --danger:    #ef4444;
  --radius:    10px;
  --radius-lg: 16px;
  --shadow:    0 8px 32px rgba(0,0,0,.45);
  --transition: 0.15s ease;
}

[data-theme="light"] {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface2:  #e9eef5;
  --border:    #cbd5e1;
  --text:      #0f172a;
  --muted:     #64748b;
  --accent:    #6366f1;
  --accent-h:  #4f46e5;
  --accent-l:  #4f46e5;
  --success:   #16a34a;
  --danger:    #dc2626;
  --shadow:    0 8px 32px rgba(0,0,0,.12);
}

/* Theme toggle button */
.theme-toggle {
  padding: 5px 8px;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface2); color: var(--text); }

html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ============================================================
   BUTTONS
   ============================================================ */

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 9px 18px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  white-space: nowrap;
}
button:active:not(:disabled) { transform: scale(0.96); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

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

.btn-secondary-action { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary-action:hover:not(:disabled) { background: var(--border); }

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

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }

.btn-ghost-danger { background: transparent; color: var(--muted); }
.btn-ghost-danger:hover:not(:disabled) { background: rgba(239,68,68,.12); color: var(--danger); }

.icon-btn {
  padding: 5px 7px;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }

/* ============================================================
   INPUTS
   ============================================================ */

input[type="text"] {
  width: 100%;
  padding: 9px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--muted); }

/* ============================================================
   SCREENS
   ============================================================ */

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ============================================================
   LOBBY
   ============================================================ */

.lobby-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 44px 48px;
  width: 100%;
  max-width: 660px;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
  position: relative;
}

.logo .theme-toggle {
  margin-left: auto;
  position: absolute;
  right: 0;
}

.logo h1 {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.field-group {
  margin-bottom: 28px;
}
.field-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 7px;
}

.lobby-actions {
  display: flex;
  gap: 0;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.lobby-col {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lobby-col h2 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lobby-divider {
  width: 1px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}
.lobby-divider span {
  position: absolute;
  background: var(--surface);
  padding: 4px 6px;
  font-size: 0.75rem;
  color: var(--muted);
  border-radius: 4px;
}

.status-msg {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 14px;
  min-height: 18px;
}

.error-msg {
  color: #f87171;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 8px;
  min-height: 20px;
}

/* ============================================================
   ROOM — HEADER
   ============================================================ */

#room {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 0;
  align-items: stretch;
  justify-content: flex-start;
}

.room-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.room-title-group {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 0;
  flex: 1;
}

.room-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.room-id-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 0.82rem;
  color: var(--muted);
}
.room-id-badge strong { color: var(--text); letter-spacing: 0.08em; }

.copy-toast {
  font-size: 0.8rem;
  color: var(--success);
  animation: fadeIn 0.15s ease;
}

/* ============================================================
   ROOM — BODY
   ============================================================ */

.room-body {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}

.panel-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 12px;
}

/* ---- Story panel ---- */

  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .scale-select {
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition), background var(--transition);
  }
  .scale-select:hover { border-color: var(--accent); }
  .scale-select:focus { border-color: var(--accent); background: var(--surface2); }
  .scale-select option { color: var(--text); background: var(--surface); }


.vote-progress {
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
}

.story-input-row {
  display: flex;
  gap: 9px;
}
.story-input-row input { flex: 1; }

.current-story-text {
  margin-top: 12px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  min-height: 24px;
  word-break: break-word;
}

/* ---- Card deck ---- */

.card-deck {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

  .poker-card {
    width: 62px;
    height: 86px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    position: relative;
    transition: border-color var(--transition), background var(--transition),
              transform 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
  position: relative;
}

.poker-card:hover:not(:disabled):not(.dimmed) {
  border-color: var(--accent);
  background: var(--surface2);
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(99,102,241,.3);
}

.poker-card.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  transform: translateY(-8px);
  box-shadow: 0 10px 28px rgba(99,102,241,.55);
}

.poker-card.dimmed {
  opacity: 0.4;
  cursor: default;
}

.card-icon {
  display: block;
  pointer-events: none;
  width: 36px;
  height: 36px;
}

.card-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  background: var(--text);
  color: var(--bg);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  transform-origin: bottom center;
}
.card-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--text);
}
.poker-card:hover .card-tooltip,
.vote-badge:hover .card-tooltip {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ---- Actions row ---- */

.actions-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions-row button { padding: 11px 24px; font-size: 0.95rem; }

/* ---- Results ---- */

.results-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.result-bar-item {
  display: grid;
  grid-template-columns: 40px 1fr 70px;
  align-items: center;
  gap: 10px;
}

.result-bar-label {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-l);
  text-align: right;
}

.result-bar-track {
  height: 20px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

.result-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-l));
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 6px;
}

.result-bar-count {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 600;
}
.result-bar-sub { color: var(--muted); font-weight: 400; }

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stat-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-val {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent-l);
  line-height: 1.2;
}

/* ---- Players ---- */

.players-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.88rem;
  transition: border-color var(--transition);
}

.player-chip.me { border-color: var(--accent); }

.host-badge {
  font-size: 0.9rem;
  opacity: 0.8;
}

.player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--transition);
}
.player-dot.voted   { background: var(--success); }
.player-dot.revealed { background: var(--accent); }

.player-name { color: var(--text); }

.rename-trigger {
  cursor: pointer;
  text-decoration: underline dotted var(--muted);
}
.rename-trigger:hover { color: var(--accent-l); }

.vote-badge {
  background: var(--accent);
  border-radius: 5px;
  padding: 1px 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  margin-left: 2px;
  position: relative;
}

/* ============================================================
   RENAME MODAL
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.18s ease;
}

.modal-box h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 600px) {
  .lobby-card { padding: 28px 18px; }
  .lobby-actions { flex-direction: column; }
  .lobby-divider { width: 100%; height: 1px; flex-direction: row; }
  .lobby-divider span { top: auto; }

  .room-header { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  .room-body { padding: 16px 12px 40px; }
  .panel { padding: 16px; }

  .card-deck { gap: 8px; }
  .poker-card { width: 54px; height: 74px; font-size: 1.1rem; }

  .result-bar-item { grid-template-columns: 32px 1fr 60px; }
  .stat-val { font-size: 1.2rem; }

  .actions-row button { flex: 1; justify-content: center; }
}
