:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-card-subtle: #334155;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --primary: #38bdf8;
  --primary-hover: #0ea5e9;
  --primary-glow: rgba(56, 189, 248, 0.35);

  --accent-success: #10b981;
  --accent-success-hover: #059669;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --accent-danger-glow: rgba(239, 68, 68, 0.45);

  --ring-size: 440px;
  --ring-circumference: 1225.22; /* 2 * PI * 195 */
  --led-font: 'Orbitron', 'Inter', monospace;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1540px;
  margin: 0 auto;
  padding: 16px 24px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  margin-bottom: 20px;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
}

.btn-back:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(-2px);
}

.header-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0f172a;
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.header-icon svg {
  width: 24px;
  height: 24px;
}

.header-titles h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-action, .btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-action:hover, .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Layout */
.main-content {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  flex: 1;
}

/* Cột trái (Sidebar) */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-card {
  background: var(--bg-card);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  padding: 18px 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.panel-header {
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e2e8f0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Mode selector */
.mode-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  padding: 4px;
  border-radius: 12px;
}

.btn-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-mode.active {
  background: var(--primary);
  color: #0f172a;
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* Preset Grid */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.btn-preset {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 8px;
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.btn-preset:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-preset.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: var(--primary);
  color: var(--primary);
}

.custom-time-section {
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.section-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}

.custom-inputs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.input-unit {
  flex: 1;
  text-align: center;
}

.input-unit input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  padding: 6px;
  outline: none;
  transition: border-color 0.2s;
}

.input-unit input:focus {
  border-color: var(--primary);
}

.input-unit span {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.colon {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.w-full {
  width: 100%;
}
.mt-2 {
  margin-top: 8px;
}
.mt-3 {
  margin-top: 12px;
}
.mb-0 {
  margin-bottom: 0 !important;
}

.form-group {
  margin-bottom: 12px;
}

.form-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  color: #ffffff;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--primary);
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toggle-option {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.toggle-option input {
  display: none;
}

.toggle-slider {
  width: 38px;
  height: 20px;
  background: #334155;
  border-radius: 20px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-option input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-option input:checked + .toggle-slider::after {
  transform: translateX(18px);
}

.option-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}

.btn-text:hover {
  text-decoration: underline;
  opacity: 0.9;
}

/* Khu vực hiển thị đồng hồ trung tâm */
.timer-display-area {
  display: flex;
  flex-direction: column;
}

.timer-stage {
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 36px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 580px;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.4), 0 8px 30px rgba(0, 0, 0, 0.3);
  transition: background 0.3s ease;
}

/* Stage Banner */
.stage-banner {
  text-align: center;
  margin-bottom: 24px;
}

.stage-banner h2 {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  color: #ffffff;
  text-transform: uppercase;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  margin-bottom: 4px;
}

.stage-banner p {
  font-size: 1.05rem;
  color: var(--text-muted);
}

/* Circular Timer */
.circular-timer-wrapper {
  position: relative;
  width: var(--ring-size);
  height: var(--ring-size);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0 30px;
}

.progress-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.05);
  stroke-width: 14;
}

.ring-progress {
  fill: none;
  stroke: var(--primary);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 1225.22;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.3s ease, stroke 0.4s ease, filter 0.4s ease;
  filter: drop-shadow(0 0 10px var(--primary-glow));
}

.timer-inner-content {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 80%;
  height: 80%;
}

.timer-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 12px;
  text-transform: uppercase;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.led-digits {
  font-family: var(--led-font);
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.04em;
  color: #ffffff;
  text-shadow: 0 0 25px rgba(56, 189, 248, 0.45), 0 0 50px rgba(56, 189, 248, 0.2);
  margin-bottom: 12px;
  user-select: none;
}

.timer-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.percent-badge {
  background: rgba(56, 189, 248, 0.15);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Time Up Banner */
.time-up-banner {
  display: none;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(185, 28, 28, 0.3));
  border: 2px solid var(--accent-danger);
  border-radius: 16px;
  padding: 16px 28px;
  margin-bottom: 24px;
  align-items: center;
  gap: 14px;
  animation: pulse-danger 1s infinite alternate;
}

.time-up-banner.show {
  display: flex;
}

@keyframes pulse-danger {
  0% {
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.3);
    transform: scale(0.99);
  }
  100% {
    box-shadow: 0 0 35px rgba(239, 68, 68, 0.7);
    transform: scale(1.02);
  }
}

.time-up-icon {
  font-size: 2rem;
}

.time-up-text {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

/* Controls */
.timer-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 10;
}

.btn-ctl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.btn-ctl:active {
  transform: scale(0.96);
}

.btn-ctl-start {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  min-width: 170px;
}

.btn-ctl-start:hover {
  background: linear-gradient(135deg, #34d399, #10b981);
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

.btn-ctl-start.paused {
  background: linear-gradient(135deg, #f59e0b, #d97706);
}

.btn-ctl-start.paused:hover {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.4);
}

.btn-ctl-reset {
  background: #334155;
  color: #f1f5f9;
}

.btn-ctl-reset:hover {
  background: #475569;
}

.btn-ctl-lap {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-ctl-lap:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-ctl-plus {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--primary);
  padding: 14px 20px;
}

.btn-ctl-plus:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: var(--primary);
}

/* Laps history */
.lap-history-card {
  margin-top: 32px;
  width: 100%;
  max-width: 600px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px 20px;
}

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

.lap-header h4 {
  font-size: 0.9rem;
  color: #cbd5e1;
}

.btn-clear-laps {
  background: none;
  border: none;
  color: var(--accent-danger);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-clear-laps:hover {
  text-decoration: underline;
}

.lap-list-wrapper {
  max-height: 180px;
  overflow-y: auto;
}

.lap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  text-align: left;
}

.lap-table th, .lap-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.lap-table th {
  color: var(--text-dim);
  font-weight: 600;
}

.lap-table td {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-main);
}

/* Cảnh báo màu sắc đồng hồ */
.timer-warning .ring-progress {
  stroke: var(--accent-warning);
  filter: drop-shadow(0 0 15px rgba(245, 158, 11, 0.5));
}
.timer-warning .led-digits {
  color: #fef08a;
  text-shadow: 0 0 25px rgba(245, 158, 11, 0.5);
}

.timer-danger .ring-progress {
  stroke: var(--accent-danger);
  filter: drop-shadow(0 0 20px var(--accent-danger-glow));
}
.timer-danger .led-digits {
  color: #fca5a5;
  text-shadow: 0 0 35px var(--accent-danger-glow);
  animation: led-blink 1s infinite alternate;
}

@keyframes led-blink {
  0% { opacity: 1; }
  100% { opacity: 0.75; }
}

/* Chế độ Toàn Màn Hình (Fullscreen Projector) */
:fullscreen .app-container,
:-webkit-full-screen .app-container {
  max-width: 100vw;
  height: 100vh;
  padding: 0;
  border-radius: 0;
}

:fullscreen .app-header,
:-webkit-full-screen .app-header {
  border-radius: 0;
  margin-bottom: 0;
  background: rgba(15, 23, 42, 0.95);
  border: none;
  border-bottom: 1px solid var(--border-color);
  padding: 10px 24px;
}

:fullscreen .main-content,
:-webkit-full-screen .main-content {
  grid-template-columns: 1fr;
  height: calc(100vh - 65px);
  gap: 0;
}

:fullscreen .sidebar-panel,
:-webkit-full-screen .sidebar-panel {
  display: none; /* Ẩn sidebar khi trình chiếu toàn màn hình để số LED to nhất */
}

:fullscreen .timer-stage,
:-webkit-full-screen .timer-stage {
  border-radius: 0;
  border: none;
  height: 100%;
  min-height: auto;
  justify-content: space-evenly;
  padding: 20px 40px;
}

:fullscreen .stage-banner h2,
:-webkit-full-screen .stage-banner h2 {
  font-size: 2.8rem;
}

:fullscreen .stage-banner p,
:-webkit-full-screen .stage-banner p {
  font-size: 1.3rem;
}

:fullscreen .circular-timer-wrapper,
:-webkit-full-screen .circular-timer-wrapper {
  --ring-size: min(65vh, 600px);
  width: var(--ring-size);
  height: var(--ring-size);
}

:fullscreen .led-digits,
:-webkit-full-screen .led-digits {
  font-size: clamp(4.5rem, 9vw, 8rem);
}

:fullscreen .btn-ctl,
:-webkit-full-screen .btn-ctl {
  padding: 18px 36px;
  font-size: 1.25rem;
  border-radius: 16px;
}

/* Responsive */
@media (max-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  .sidebar-panel {
    order: 2;
  }
  .timer-display-area {
    order: 1;
  }
}

@media (max-width: 640px) {
  .app-container {
    padding: 10px;
  }
  .circular-timer-wrapper {
    --ring-size: 320px;
  }
  .led-digits {
    font-size: 3.5rem;
  }
  .stage-banner h2 {
    font-size: 1.3rem;
  }
  .btn-ctl {
    padding: 10px 18px;
    font-size: 0.9rem;
  }
}
