* { box-sizing: border-box; }

:root {
  --bg: #0b0d14;
  --surface: #12141f;
  --surface-2: #171a28;
  --border: #232739;
  --text: #e8e9ee;
  --text-dim: #9198ac;
  --accent: #6d7bff;
  --accent-2: #9b6dff;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 16px;
  --radius-sm: 10px;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #191d2c 0%, var(--bg) 60%);
  color: var(--text);
  margin: 0;
  padding: 0 0 40px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.icon {
  width: 16px; height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
  margin-right: 6px;
  opacity: 0.85;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(18, 20, 31, 0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; flex: 1; }
.brandMark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 14px rgba(109, 123, 255, 0.35);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -0.5px;
}
.brandName { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }

#userInfo { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-dim); }

main#app {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 20px;
  max-width: 1080px;
  margin: 28px auto 0;
  padding: 0 20px;
  animation: fadeIn 0.35s ease;
}

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

.card {
  background: linear-gradient(180deg, var(--surface) 0%, #101320 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 10px 30px rgba(0,0,0,0.28);
  transition: border-color 0.2s ease;
}
.cardHead { margin-bottom: 14px; }
.card h2 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
  display: flex;
  align-items: center;
}

#videoWrap { position: relative; width: 100%; border-radius: var(--radius-sm); overflow: hidden; background: #05060a; aspect-ratio: 4 / 3; }
video, canvas#overlay { display: block; width: 100%; height: 100%; object-fit: cover; }
canvas#overlay { position: absolute; top: 0; left: 0; }

#calibrationOverlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  background: rgba(5,6,10,0.78);
  color: #fff;
}
.ringSvg { width: 88px; height: 88px; position: absolute; transform: rotate(-90deg); }
.ringTrack, .ringProgress {
  fill: none;
  stroke-width: 5;
}
.ringTrack { stroke: rgba(255,255,255,0.12); }
.ringProgress {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 276.5;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}
#calibrationCount { font-size: 32px; font-weight: 800; }
#calibrationText { font-size: 13px; color: var(--text-dim); margin-top: 44px; }

#wakeImageOverlay {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px;
  background: rgba(5,6,10,0.88);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
}
#wakeImageText {
  color: var(--bad);
  font-size: clamp(28px, 6vw, 56px);
  font-weight: 800;
  letter-spacing: -0.5px;
  text-shadow: 0 0 24px rgba(248,113,113,0.6);
  animation: pulseHard 0.6s infinite;
}
#wakeImage {
  max-width: min(90vw, 520px);
  max-height: 68vh;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  object-fit: contain;
}

.status {
  margin-top: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  text-align: center;
  border: 1px solid transparent;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.status.idle { background: var(--surface-2); color: var(--text-dim); border-color: var(--border); }
.status.focused { background: rgba(52, 211, 153, 0.12); color: var(--good); border-color: rgba(52,211,153,0.3); }
.status.drowsy-warn { background: rgba(251, 191, 36, 0.12); color: var(--warn); border-color: rgba(251,191,36,0.3); }
.status.asleep-alert { background: rgba(248, 113, 113, 0.28); color: #fff; border-color: rgba(248,113,113,0.7); animation: pulseHard 0.6s infinite; font-weight: 800; }
.status.away { background: var(--surface-2); color: var(--text-dim); border-color: var(--border); }
.status.posture-ok { background: rgba(52, 211, 153, 0.1); color: var(--good); border-color: rgba(52,211,153,0.25); }
.status.posture-bad { background: rgba(251, 191, 36, 0.14); color: var(--warn); border-color: rgba(251,191,36,0.3); }
.status.distraction-ok { background: rgba(52, 211, 153, 0.1); color: var(--good); border-color: rgba(52,211,153,0.25); }
.status.distraction-bad { background: rgba(248, 113, 113, 0.16); color: var(--bad); border-color: rgba(248,113,113,0.4); animation: pulse 1s infinite; }

.extraToggles { display: flex; gap: 16px; margin-top: 14px; flex-wrap: wrap; }
.toggleRow {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.toggleRow input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.perfNote { font-size: 11.5px; color: var(--text-dim); opacity: 0.75; margin: 8px 0 0; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

@keyframes pulseHard {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(1.015); }
}

#timerDisplay {
  font-size: 54px;
  font-weight: 800;
  text-align: center;
  margin: 6px 0 16px;
  letter-spacing: -1.5px;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff, #c7cbe0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.timerSettings { display: flex; gap: 16px; margin-bottom: 4px; font-size: 13px; color: var(--text-dim); }
.timerSettings input {
  width: 56px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 6px;
  margin-left: 6px;
  font-family: inherit;
}

#timerControls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
button {
  border: none;
  border-radius: 9px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: opacity 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.35; cursor: not-allowed; }

.primaryBtn { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 14px rgba(109,123,255,0.3); }
.primaryBtn:hover:not(:disabled) { box-shadow: 0 6px 18px rgba(109,123,255,0.45); }
.secondaryBtn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.secondaryBtn:hover:not(:disabled) { background: #1d2133; border-color: #2c3148; }
.dangerBtn { background: rgba(248, 113, 113, 0.12); color: var(--bad); border: 1px solid rgba(248,113,113,0.3); }
.dangerBtn:hover:not(:disabled) { background: rgba(248, 113, 113, 0.2); }
.ghostBtn { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.ghostBtn:hover { color: var(--text); border-color: #2c3148; }
.fullWidth { width: 100%; margin-top: 10px; }

#roundInfo { margin-top: 12px; font-size: 13px; color: var(--text-dim); }
#roundInfo span { color: var(--text); font-weight: 700; }

#liveStats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.statTile {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.statLabel { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.statValue { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.statValue small { font-size: 12px; font-weight: 600; opacity: 0.6; margin-left: 2px; }
.statTile.focus .statValue { color: var(--good); }
.statTile.drowsy .statValue { color: var(--warn); }
.statTile.sleep .statValue { color: var(--bad); }
.statTile.away .statValue { color: var(--text-dim); }

.tableWrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: rgba(255,255,255,0.02); }

.emptyState { text-align: center; color: var(--text-dim); font-size: 13px; padding: 24px 0; }

#loginGate { text-align: center; color: var(--text-dim); margin-top: 60px; font-size: 14px; }

@media (max-width: 800px) {
  main#app { grid-template-columns: 1fr; }
  #liveStats { grid-template-columns: 1fr; }
}
