:root {
  --bg: #0f1216;
  --surface: #181c22;
  --surface-2: #222831;
  --text: #f2f4f7;
  --muted: #9aa4b2;
  --line: #2e3540;
  --accent: #3fb68b;
  --amber: #f2c14e;
  --orange: #f08a3c;
  --red: #e5484d;
  --state: var(--accent);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .6em 1.1em;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.ghost { background: transparent; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06130e; font-weight: 600; }
button.danger { color: var(--red); }
button.active { border-color: var(--accent); color: var(--accent); }

input[type=text], input[type=number], select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45em .7em;
}

/* Header */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  flex-wrap: wrap;
}
.who { display: flex; gap: 10px; flex-wrap: wrap; flex: 1 1 320px; }
.who input { flex: 1 1 200px; min-width: 0; font-size: 1.1rem; background: transparent; border-color: transparent; }
.who input:hover, .who input:focus { border-color: var(--line); background: var(--surface); }
#studentName { font-weight: 600; font-size: 1.35rem; }
.top-actions { display: flex; gap: 8px; }

/* Stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  text-align: center;
}
.status-line {
  font-size: clamp(1.2rem, 3vw, 2.2rem);
  font-weight: 600;
  color: var(--state);
  letter-spacing: .02em;
  min-height: 1.4em;
}
.timer {
  font-size: clamp(5.5rem, 24vw, 24rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--state);
  margin: .05em 0;
  transition: color .4s;
}
.remaining {
  font-size: clamp(1.1rem, 2.6vw, 2rem);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.progress {
  position: relative;
  width: min(900px, 100%);
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  margin: 22px 0 26px;
  overflow: visible;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--state);
  border-radius: 999px;
  transition: background .4s;
}
.progress-marks { position: absolute; inset: 0; pointer-events: none; }
.progress-marks span {
  position: absolute;
  top: -6px;
  width: 2px;
  height: 22px;
  background: var(--muted);
  opacity: .6;
}
.progress-marks span.done { background: var(--text); opacity: 1; }

.controls { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.controls button { font-size: 1.25rem; padding: .7em 1.5em; min-width: 9em; }

/* State colours */
body.state-1 { --state: var(--amber); }
body.state-2 { --state: var(--orange); }
body.state-3 { --state: var(--red); }
body.overtime .timer { animation: pulse 1.2s ease-in-out infinite; }
body.paused .timer { opacity: .55; }
@keyframes pulse { 50% { opacity: .55; } }

/* Subtitles */
.subs-wrap {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 20px 18px;
}
.subs-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; color: var(--muted); }
.lang-pick { display: flex; align-items: center; gap: 8px; }
.subs-status { font-size: .95rem; }
.subs {
  min-height: 0;
  font-size: clamp(1.2rem, 2.8vw, 2.3rem);
  line-height: 1.35;
  margin-top: 8px;
}
.subs:empty { display: none; }
.subs p { margin: .15em 0; }
.subs p.old { color: var(--muted); }
.subs p.pending { color: var(--muted); font-style: italic; }
body.translating .subs { min-height: 4.2em; }

/* Banner */
.banner {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .55);
  z-index: 50;
  padding: 16px;
}
.banner[hidden] { display: none; }
.banner-text {
  background: var(--state);
  color: #0b0d10;
  font-size: clamp(1.6rem, 5vw, 4.2rem);
  font-weight: 700;
  padding: .8em 1.2em;
  border-radius: 20px;
  max-width: 1100px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

/* Drawer */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(640px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  z-index: 40;
  padding: 16px 20px 40px;
  box-shadow: -20px 0 50px rgba(0,0,0,.4);
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer h2 { margin: 0; }
.panel { border-top: 1px solid var(--line); padding: 14px 0; }
.panel h3 { margin: 0 0 6px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .9rem; margin: 0 0 10px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.field select, .field input { flex: 1; max-width: 360px; min-width: 0; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; }
.alerts-table input[type=number] { width: 4.2em; }
.alerts-table input[type=text] { width: 100%; }
.alerts-table td:last-child { white-space: nowrap; }
.alerts-table td button { padding: .3em .6em; }
.table-scroll { overflow-x: auto; }
.history-table td { white-space: nowrap; }
kbd { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .35em; font-size: .85em; }

@media (max-width: 600px) {
  .top, .subs-wrap { padding-left: 16px; padding-right: 16px; }
  .controls button { min-width: 0; flex: 1 1 40%; font-size: 1.05rem; padding: .7em .8em; }
  .alerts-table thead { display: none; }
}
