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

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242836;
  --text-primary: #f0f2f5;
  --text-secondary: #a0a4b0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --focus-color: #ef4444;
  --break-color: #22c55e;
  --border: #2e3244;
}

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100vh; display: flex; flex-direction: column; }

.screen { display: none; flex: 1; flex-direction: column; min-height: 0; }
.screen.active { display: flex; }

/* ========== LOGIN ========== */
#login-screen {
  background: linear-gradient(135deg, #0f1117 0%, #1a1d27 50%, #111827 100%);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  text-align: center;
}

.logo { font-size: 32px; margin-bottom: 6px; }
.subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }

.avatar-picker {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 20px;
}

.avatar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.avatar-btn:hover { border-color: var(--accent); }
.avatar-btn.picked { border-color: var(--accent); background: rgba(99,102,241,0.15); }
.avatar-emoji { font-size: 32px; }
.avatar-label { font-size: 13px; font-weight: 600; }

#nickname-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.2s;
}
#nickname-input:focus { border-color: var(--accent); }
#nickname-input.shake { animation: shake 0.4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  padding: 14px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.small { padding: 10px 14px; font-size: 14px; width: auto; }

.hint { font-size: 12px; color: var(--text-secondary); margin-top: 14px; }

/* ========== ROOM ========== */
.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.room-title { font-size: 15px; font-weight: 600; }
.online-count { font-size: 13px; color: var(--text-secondary); }

.room-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}

/* --- video --- */
.video-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-content: start;
  overflow-y: auto;
  min-height: 0;
}
.video-panel:has(.remote-video-wrap) { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.video-card {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  min-height: 180px;
}
.video-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  display: block;
}
#local-video { transform: scaleX(-1); }

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  gap: 8px;
  cursor: pointer;
  transition: opacity 0.3s;
  z-index: 2;
}
.video-overlay.hidden { opacity: 0; pointer-events: none; }
.video-icon { font-size: 36px; }
.video-overlay-text { font-size: 13px; color: var(--text-secondary); }

.video-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  gap: 8px;
  pointer-events: none;
}
.label-name { font-weight: 600; color: #fff; }
.label-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--idle-color, #6b7280);
  color: #fff;
}

.video-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 3;
}
.ctrl-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  border: none;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:hover { background: var(--accent); transform: scale(1.08); }
.ctrl-btn.active { background: var(--accent); }
.ctrl-btn.muted { background: rgba(239,68,68,0.7); }

.remote-timer-chip {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  background: rgba(0,0,0,0.55);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 12px;
  z-index: 3;
}
.remote-timer-chip.running { box-shadow: 0 0 0 2px rgba(99,102,241,0.6); }
.chip-mode.focus { color: #ff6b6b; }
.chip-mode.break { color: #51cf66; }
.chip-time { font-variant-numeric: tabular-nums; font-weight: 700; color: #ffd54f; }

/* --- right panel --- */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
}

.timer-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 16px;
  text-align: center;
}
.timer-modes {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}
.mode-label {
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 16px;
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.mode-label.active.focus { background: rgba(239,68,68,0.15); color: #ff6b6b; border-color: rgba(239,68,68,0.4); }
.mode-label.active.break { background: rgba(34,197,94,0.15); color: #51cf66; border-color: rgba(34,197,94,0.4); }

.timer-display {
  font-size: 56px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  line-height: 1;
  margin: 8px 0 10px;
}
.timer-today {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}
.timer-today b { color: var(--text-primary); font-size: 14px; }

.timer-controls { display: flex; gap: 8px; justify-content: center; }
.timer-controls .btn-primary,
.timer-controls .btn-secondary,
.timer-controls .btn-ghost { flex: 1; min-width: 0; }

.section-title {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
}

/* summary */
.summary-section, .timerboard-section, .chat-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.summary-list, .timer-board {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.summary-empty, .board-empty {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding: 14px 0;
}
.summary-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 13px;
}
.summary-medal { text-align: center; }
.summary-name { font-weight: 600; }
.summary-today { font-size: 12px; text-align: right; }
.summary-today b { color: #ffd54f; }
.summary-total { grid-column: 2 / 4; font-size: 11px; color: var(--text-secondary); }

/* timer board */
.board-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  font-size: 13px;
}
.board-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}
.status-online { background: #6b7280; color: #fff; }
.status-focusing { background: #ef4444; color: #fff; }
.status-resting { background: #22c55e; color: #fff; }
.status-away { background: #f59e0b; color: #fff; }
.board-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-secondary); }
.board-time.running { color: #ffd54f; animation: pulse 1.5s infinite; }
.board-mode { text-align: center; width: 22px; }
@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* chat */
.chat-section { display: flex; flex-direction: column; min-height: 220px; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  margin-bottom: 8px;
}
.chat-msg {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border-radius: 8px;
}
.chat-name { font-weight: 600; color: var(--accent); white-space: nowrap; }
.chat-text { word-break: break-word; }
.chat-time { font-size: 11px; color: var(--text-secondary); white-space: nowrap; align-self: end; }
.chat-system { text-align: center; font-size: 12px; padding: 4px; }
.chat-system-text { color: var(--text-secondary); background: transparent; }

.chat-input-row { display: flex; gap: 8px; }
#chat-input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
#chat-input:focus { border-color: var(--accent); }

/* scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .room-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
  }
  .video-panel { max-height: 50vh; }
  .video-card { min-height: 160px; }
  .timer-display { font-size: 48px; }
  .summary-row { grid-template-columns: 20px 1fr auto; }
}

@media (max-width: 500px) {
  .room-main { padding: 10px; gap: 10px; }
  .video-card { min-height: 140px; }
  .timer-display { font-size: 42px; }
  .timer-controls .btn-primary,
  .timer-controls .btn-secondary,
  .timer-controls .btn-ghost { padding: 8px 10px; font-size: 13px; }
  .ctrl-btn { width: 32px; height: 32px; font-size: 13px; }
  .room-header { padding: 8px 14px; }
  .room-title { font-size: 14px; }
}
