/* ============================================================
   CubeTimer — Polished Rubik's Cube Timer
   ============================================================ */

/* ── CSS Custom Properties ────────────────────────────────── */
:root {
  --bg: #0f1117;
  --bg-panel: #161b27;
  --bg-card: #1e2535;
  --bg-card-hover: #252d40;
  --bg-input: #252d40;
  --border: #2a3148;
  --border-subtle: #1e2535;
  --text: #e8ecf4;
  --text-muted: #7a8299;
  --text-faint: #4a5268;
  --accent: #5b8af5;
  --accent-hover: #7ba1ff;
  --accent-faint: rgba(91, 138, 245, 0.12);
  --green: #3ecf8e;
  --green-faint: rgba(62, 207, 142, 0.12);
  --red: #f56565;
  --red-faint: rgba(245, 101, 101, 0.12);
  --yellow: #f6c90e;
  --yellow-faint: rgba(246, 201, 14, 0.12);
  --orange: #f59e0b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Consolas', 'Liberation Mono', monospace;
  --header-h: 56px;
  --transition: 150ms ease;
}

[data-theme="light"] {
  --bg: #f0f2f8;
  --bg-panel: #ffffff;
  --bg-card: #f5f7fc;
  --bg-card-hover: #eef0f8;
  --bg-input: #eef0f8;
  --border: #d8dce8;
  --border-subtle: #e8eaf2;
  --text: #1a1f33;
  --text-muted: #5a6180;
  --text-faint: #9aa0b8;
  --accent: #4070e8;
  --accent-hover: #2f5cd4;
  --accent-faint: rgba(64, 112, 232, 0.1);
  --green: #16a34a;
  --green-faint: rgba(22, 163, 74, 0.1);
  --red: #dc2626;
  --red-faint: rgba(220, 38, 38, 0.1);
  --yellow: #d97706;
  --yellow-faint: rgba(217, 119, 6, 0.1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.14);
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

button { cursor: pointer; font-family: inherit; border: none; background: none; }
svg { display: block; flex-shrink: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* ── Layout ────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 600px;
}

/* ── Header ────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Main layout ───────────────────────────────────────────── */
#main {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 260px;
  gap: 0;
  overflow: hidden;
}

/* ── Panels ────────────────────────────────────────────────── */
#stats-panel,
#solves-panel {
  background: var(--bg-panel);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#stats-panel { border-right: 1px solid var(--border); }
#solves-panel { border-left: 1px solid var(--border); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

/* ── Stats grid ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  transition: background var(--transition), border-color var(--transition);
}

.stat-card:hover { background: var(--bg-card-hover); }

.stat-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* ── Best stats ────────────────────────────────────────────── */
.stats-bests {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.bests-header {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.best-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.best-row:last-child { border-bottom: none; }

.best-label {
  font-size: 12px;
  color: var(--text-muted);
}

.best-value {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--yellow);
}

/* ── Center panel ──────────────────────────────────────────── */
#center-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 0;
  position: relative;
  overflow: hidden;
}

/* ── Scramble ──────────────────────────────────────────────── */
#scramble-container {
  width: 100%;
  max-width: 680px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
}

#profile-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.profile-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 220px;
}

.profile-toolbar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

#profile-select {
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font: inherit;
}

.profile-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#scramble-display {
  min-height: 44px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

#scramble-text {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.6;
  letter-spacing: 0.3px;
  word-spacing: 6px;
}

#scramble-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Timer area ────────────────────────────────────────────── */
#timer-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  user-select: none;
}

#timer-display {
  padding: 12px 0;
  transition: color 200ms ease;
  cursor: default;
}

#timer-text {
  font-family: var(--font-mono);
  font-size: clamp(60px, 10vw, 100px);
  font-weight: 300;
  letter-spacing: -4px;
  line-height: 1;
  transition: color 200ms ease, transform 150ms ease;
}

/* Timer states */
.timer-idle #timer-text { color: var(--text); }
.timer-ready #timer-text { color: var(--green); }
.timer-running #timer-text { color: var(--accent); }
.timer-stopped #timer-text { color: var(--text); }
.timer-dnf #timer-text { color: var(--red); }
.timer-penalty #timer-text { color: var(--yellow); }

/* Subtle pulse animation while running */
@keyframes timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

.timer-running #timer-text {
  animation: timer-pulse 2s ease-in-out infinite;
}

#timer-hint {
  font-size: 13px;
  color: var(--text-muted);
}

#hint-text kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-style: normal;
}

/* ── Last solve actions ────────────────────────────────────── */
#last-solve-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 10px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

#last-solve-label {
  font-size: 12px;
  color: var(--text-muted);
}

.last-solve-time-val {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.solve-action-btns {
  display: flex;
  gap: 6px;
}

/* ── Keyboard hints bar ────────────────────────────────────── */
#keyboard-hints {
  position: absolute;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-faint);
}

.kbd-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  font-style: normal;
  margin-right: 2px;
}

.kbd-hint-sep { color: var(--text-faint); }

/* ── Solves list ───────────────────────────────────────────── */
#solves-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}

#solves-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.solve-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  position: relative;
}

.solve-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
}

.solve-item.solve-pb {
  border-left: 3px solid var(--yellow) !important;
}

.solve-num {
  font-size: 10px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  width: 22px;
  flex-shrink: 0;
  text-align: right;
}

.solve-time {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

.solve-time.dnf { color: var(--red); }
.solve-time.plus2 { color: var(--yellow); }

.solve-delete-btn {
  opacity: 0;
  transition: opacity var(--transition);
  color: var(--text-faint);
  padding: 2px 4px;
  border-radius: 4px;
}

.solve-delete-btn:hover {
  color: var(--red);
  background: var(--red-faint);
}

.solve-item:hover .solve-delete-btn {
  opacity: 1;
}

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 16px;
  color: var(--text-faint);
  text-align: center;
}

.empty-state p { font-size: 13px; }
.empty-state .empty-sub { font-size: 11px; color: var(--text-faint); }
.empty-state svg { color: var(--text-faint); }

/* ── Badge ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--accent-faint);
  color: var(--accent);
  letter-spacing: 0.3px;
}

.badge-muted {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  color: var(--text);
  border: 1px solid transparent;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 3px var(--accent-faint);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--bg-card-hover);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  background: var(--red-faint);
  color: var(--red);
  border-color: transparent;
}
.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.btn-ghost.btn-danger {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost.btn-danger:hover {
  background: var(--red-faint);
  color: var(--red);
  border-color: transparent;
}

.btn-sm { font-size: 12px; padding: 5px 11px; }
.btn-xs { font-size: 11px; padding: 3px 8px; }
.btn-icon { padding: 6px; }
.btn-icon.btn-sm { padding: 5px; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.hidden { display: none; }

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

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 200ms ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.modal-body { padding: 20px; }

.modal-time {
  font-family: var(--font-mono);
  font-size: 44px;
  font-weight: 300;
  letter-spacing: -2px;
  color: var(--text);
  text-align: center;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}

.modal-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.modal-value {
  font-size: 13px;
  color: var(--text);
}

.modal-scramble {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  word-spacing: 4px;
  background: var(--bg-card);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.modal-footer .btn { flex: 1; }

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

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  #main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    overflow-y: auto;
  }

  #stats-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
  }

  #solves-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 280px;
  }

  #center-panel {
    padding: 20px 16px;
    min-height: 420px;
  }

  .stats-grid { grid-template-columns: repeat(3, 1fr); }

  #keyboard-hints { display: none; }
}

@media (max-width: 560px) {
  #scramble-text { font-size: 13px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  #header { padding: 0 12px; }

  #btn-reset-session .btn-label { display: none; }

  .profile-picker,
  .profile-toolbar-actions {
    width: 100%;
  }
}

/* ── Solve item micro-animation ────────────────────────────── */
@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

.solve-item.new-solve {
  animation: slide-in-right 250ms ease;
}

/* ── Scramble highlight animation ─────────────────────────── */
@keyframes fade-scramble {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.scramble-anim {
  animation: fade-scramble 250ms ease;
}
