:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #0b2b53;
  --muted: #657080;
  --paper: #faf9f5;
  --surface: #ffffff;
  --line: #d4d7d6;
  --green: #287a3c;
  --red: #d85e4d;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { color: inherit; }
svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.display-page { min-height: 100vh; display: grid; background: var(--ink); }
.display-shell { position: relative; width: 100%; min-height: 100vh; padding: clamp(26px, 3.3vw, 62px) clamp(34px, 4.5vw, 86px) 0; display: flex; flex-direction: column; background: var(--paper); border: clamp(6px, .55vw, 11px) solid var(--ink); overflow: hidden; }
.display-shell::before, .display-shell::after { content: ""; position: absolute; width: 130px; height: 120px; pointer-events: none; opacity: .5; background: repeating-linear-gradient(to bottom, transparent 0 21px, #9ac2de 22px 23px); border-left: 1px solid #e39a98; }
.display-shell::before { left: 34px; top: 0; }
.display-shell::after { right: 42px; bottom: 0; }
.display-header { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 40px; margin-bottom: clamp(18px, 2.5vh, 36px); padding-left: clamp(40px, 6vw, 110px); }
.brand-lockup { display: flex; align-items: center; gap: clamp(18px, 2vw, 34px); }
.school-mark { flex: 0 0 auto; width: clamp(58px, 6vw, 100px); height: auto; color: var(--ink); fill: none; stroke: currentColor; stroke-width: 2.3; }
.school-mark .mark-accent { color: var(--green); }
.brand-rule { width: 2px; height: clamp(66px, 7vw, 115px); background: var(--ink); opacity: .7; }
.display-header h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(40px, 4.3vw, 78px); font-weight: 700; line-height: .98; letter-spacing: -.04em; }
.display-header p { margin: .25em 0 0; font-size: clamp(22px, 2.15vw, 38px); letter-spacing: -.025em; }
.total-block { text-align: right; min-width: 210px; }
.total-block span { display: block; color: var(--muted); font-size: clamp(14px, 1.1vw, 21px); font-weight: 700; }
.total-block strong { display: block; margin-top: 4px; font-size: clamp(34px, 3.35vw, 60px); line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.total-block small { display: block; margin-top: 10px; color: var(--muted); font-size: clamp(14px, 1vw, 20px); font-weight: 650; }
.total-block small.is-live { color: #237844; }
.display-list { position: relative; z-index: 1; flex: 1; display: grid; grid-template-rows: repeat(5, minmax(0, 1fr)); }
.display-row { --candidate: #287a3c; position: relative; min-height: 0; display: grid; grid-template-columns: clamp(58px, 5.2vw, 96px) 1fr auto; align-items: center; gap: clamp(20px, 2.5vw, 46px); padding: clamp(10px, 1.2vh, 20px) clamp(24px, 2.5vw, 48px); border: 0; border-bottom: 2px solid var(--line); border-radius: 0; background: transparent; transition: background .2s; overflow: hidden; }
.display-row:first-child { border-top: 2px solid var(--line); }
.display-row.is-active { background: color-mix(in srgb, var(--candidate) 10%, var(--paper)); }
.candidate-number { display: grid; place-items: center; width: clamp(48px, 4.5vw, 82px); aspect-ratio: 1.12; color: var(--candidate-ink, white); background: var(--candidate); clip-path: polygon(0 0, 82% 0, 100% 50%, 82% 100%, 0 100%); font-size: clamp(27px, 3vw, 52px); font-weight: 760; line-height: 1; }
.candidate-main { min-width: 0; }
.candidate-topline { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; }
.candidate-topline h2 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; font-size: clamp(27px, 2.7vw, 48px); line-height: 1; letter-spacing: -.035em; }
.candidate-topline time { color: var(--candidate); font-size: clamp(32px, 3.6vw, 66px); line-height: 1; font-weight: 760; font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.bar-track { height: clamp(7px, .8vh, 13px); margin-top: clamp(10px, 1.25vh, 18px); background: #e3e3df; overflow: visible; }
.bar-fill { position: relative; height: 100%; min-width: 0; background: var(--candidate); transition: width .35s linear; }
.bar-fill:not([style*="width:0"]):not([style*="width: 0"])::after { content: ""; position: absolute; top: 50%; right: -16px; transform: translateY(-50%); border-left: 17px solid #e7c99c; border-top: 7px solid transparent; border-bottom: 7px solid transparent; }
.active-label { display: none; padding: .48em .75em; border-radius: 6px; color: var(--candidate-ink, white); background: var(--candidate); font-size: clamp(13px, 1vw, 18px); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.display-row.is-active .active-label { display: block; }
.display-footer { position: relative; z-index: 2; align-self: flex-start; min-width: clamp(190px, 20vw, 340px); height: clamp(45px, 6vh, 72px); display: flex; align-items: center; gap: 16px; margin-left: calc(clamp(34px, 4.5vw, 86px) * -1); padding-left: clamp(34px, 4.5vw, 86px); padding-right: 50px; color: white; background: var(--ink); clip-path: polygon(0 0, 86% 0, 100% 100%, 0 100%); font-size: clamp(18px, 1.55vw, 28px); font-weight: 700; }
.pause-icon { font-weight: 900; letter-spacing: -4px; }

.control-page { min-height: 100vh; background: var(--ink); }
.control-shell { width: min(100%, 600px); min-height: 100vh; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); background: var(--paper); border-inline: 5px solid var(--ink); }
.control-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin: -20px -18px 20px; padding: max(20px, env(safe-area-inset-top)) 18px 18px; border-bottom: 2px solid var(--green); }
.control-brand { display: flex; align-items: flex-start; gap: 11px; }
.control-brand .school-mark { width: 52px; }
.control-header h1 { margin: 3px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(30px, 8vw, 42px); line-height: 1; letter-spacing: -.035em; }
.control-header p { margin: 9px 0 0; max-width: 245px; color: var(--muted); font-size: 14px; line-height: 1.3; }
.display-link { display: inline-flex; align-items: center; gap: 7px; padding: 10px 12px; color: var(--ink); border: 1.5px solid #cdd1d7; border-radius: 8px; background: white; font-size: 14px; font-weight: 700; text-decoration: none; }
.control-list { display: grid; gap: 10px; }
.candidate-control { --candidate: #287a3c; width: 100%; min-height: 66px; display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; align-items: center; padding: 0 18px 0 0; border: 2px solid var(--candidate); border-radius: 7px; color: var(--candidate-ink, white); background: var(--candidate); overflow: hidden; text-align: left; box-shadow: 0 2px 4px rgba(11,43,83,.09); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .12s, box-shadow .12s; }
.candidate-control:active { transform: scale(.985); }
.candidate-control.is-active { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--candidate); transform: translateX(3px); }
.control-number { height: 100%; display: grid; place-items: center; color: inherit; background: rgba(0,0,0,.1); font-size: 25px; font-weight: 760; }
.control-name { min-width: 0; padding: 0 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; font-weight: 740; }
.candidate-control time { color: inherit; font-size: 19px; font-weight: 760; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.pause-button { width: 100%; height: 62px; margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 10px; border: 2px solid var(--ink); border-radius: 7px; color: var(--ink); background: white; font-size: 19px; font-weight: 780; cursor: pointer; }
.pause-button svg { fill: currentColor; stroke: none; }
.pause-button:disabled { color: #687284; background: #e0e2e4; cursor: default; }
.settings { margin-top: 14px; border: 1.5px solid #c5c9ca; border-radius: 7px; background: white; overflow: hidden; }
.settings summary { min-height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; font-size: 16px; font-weight: 740; cursor: pointer; list-style: none; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary > span { display: flex; align-items: center; gap: 10px; }
.settings[open] .chevron { transform: rotate(180deg); }
.settings-form { padding: 14px 16px 18px; border-top: 1px solid var(--line); }
.settings-form > label { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: 13px; font-weight: 700; }
.settings input { width: 100%; height: 43px; padding: 0 11px; border: 1px solid #cfd3d8; border-radius: 6px; color: var(--ink); background: #fff; font-size: 16px; }
.settings input:focus { outline: 3px solid rgba(37,99,235,.15); border-color: #2563eb; }
.settings fieldset { margin: 19px 0 14px; padding: 0; border: 0; }
.settings legend { margin-bottom: 9px; color: var(--muted); font-size: 13px; font-weight: 700; }
.settings legend small { display: block; margin-top: 3px; font-size: 11px; font-weight: 500; }
.name-editor { display: grid; grid-template-columns: 38px minmax(0, 1fr) 42px 34px; align-items: center; gap: 7px; margin-bottom: 8px; padding: 6px; border: 1px solid #d5d9dd; border-radius: 8px; background: #fff; transition: transform .15s, box-shadow .15s; }
.name-editor.is-dragging { z-index: 2; box-shadow: 0 8px 24px rgba(11,43,83,.18); transform: scale(1.01); }
.drag-handle { height: 43px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 6px; color: var(--muted); background: #f1f2f1; cursor: grab; touch-action: none; }
.drag-handle:active { cursor: grabbing; }
.drag-handle svg { width: 20px; height: 20px; }
.name-editor input[type="color"] { width: 42px; height: 43px; padding: 3px; cursor: pointer; }
.order-buttons { display: grid; gap: 2px; }
.order-buttons button { height: 20px; display: grid; place-items: center; padding: 0; border: 1px solid #d5d9dd; border-radius: 4px; background: #f7f7f5; cursor: pointer; }
.order-buttons button:disabled { opacity: .3; cursor: default; }
.order-buttons svg { width: 14px; height: 14px; }
.editor-number { display: block; color: var(--muted); font-size: 11px; font-weight: 800; line-height: 1; }
.save-button { width: 100%; height: 46px; border: 0; border-radius: 7px; color: white; background: var(--green); font-weight: 750; cursor: pointer; }
.reset-button { display: block; margin: 18px auto 0; border: 0; color: #a52f2f; background: transparent; font-size: 14px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.control-shell footer { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 24px; color: var(--muted); font-size: 14px; font-weight: 650; }
.connection-dot { width: 10px; height: 10px; border-radius: 50%; background: #b7bcc3; }
.connection-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(40,122,60,.12); }
dialog { width: min(calc(100% - 36px), 420px); padding: 24px; border: 0; border-radius: 12px; color: var(--ink); box-shadow: 0 24px 70px rgba(11,27,53,.25); }
dialog::backdrop { background: rgba(11,27,53,.45); }
dialog h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
dialog p { color: var(--muted); line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.dialog-actions button { padding: 10px 14px; border: 1px solid #cfd3d8; border-radius: 7px; background: white; font-weight: 700; }
.dialog-actions .danger { color: white; border-color: #bd3232; background: #bd3232; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 10; transform: translate(-50%, 20px); padding: 11px 16px; border-radius: 8px; color: white; background: var(--ink); opacity: 0; pointer-events: none; transition: .2s; box-shadow: 0 8px 30px rgba(11,27,53,.2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) and (orientation: landscape) {
  .display-shell { padding: 22px 30px; }
  .display-header { margin-bottom: 18px; }
  .active-label { display: none !important; }
}
@media (max-width: 700px) and (orientation: portrait) {
  .display-shell {
    min-width: 0;
    padding: 12px 8px 0;
    border-width: 4px;
  }

  .display-shell::before,
  .display-shell::after {
    display: none;
  }

  .display-header {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-left: 0;
  }

  .brand-lockup {
    min-width: 0;
    gap: 8px;
  }

  .brand-lockup > div {
    min-width: 0;
  }

  .brand-lockup .school-mark {
    width: 32px;
  }

  .brand-rule {
    width: 1px;
    height: 44px;
  }

  .display-header h1 {
    overflow: hidden;
    font-size: clamp(20px, 5.8vw, 23px);
    line-height: 1;
    letter-spacing: -.035em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .display-header p {
    overflow: hidden;
    margin-top: 4px;
    font-size: clamp(12px, 3.45vw, 14px);
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .total-block {
    min-width: 68px;
  }

  .total-block span {
    font-size: 9px;
    line-height: 1.05;
  }

  .total-block strong {
    margin-top: 3px;
    font-size: 22px;
  }

  .total-block small {
    margin-top: 4px;
    max-width: 80px;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .display-list {
    min-width: 0;
    width: 100%;
  }

  .display-row {
    min-width: 0;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    padding: 8px 4px;
  }

  .candidate-number {
    width: 32px;
    font-size: 19px;
  }

  .candidate-main {
    min-width: 0;
    width: 100%;
  }

  .candidate-topline {
    min-width: 0;
    align-items: center;
    gap: 8px;
  }

  .candidate-topline h2 {
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible;
    font-size: clamp(17px, 5.2vw, 22px);
    line-height: 1.05;
    text-overflow: clip;
    white-space: normal;
  }

  .candidate-topline time {
    flex: 0 0 auto;
    font-size: clamp(19px, 5.8vw, 24px);
  }

  .bar-track {
    height: 6px;
    margin-top: 8px;
    overflow: hidden;
  }

  .bar-fill::after {
    display: none;
  }

  .active-label {
    display: none !important;
  }

  .display-footer {
    min-width: 155px;
    height: 40px;
    gap: 10px;
    margin-left: -8px;
    padding-left: 16px;
    padding-right: 34px;
    font-size: 15px;
  }
}

@media (max-width: 620px) {
  .control-header p { max-width: 230px; }
  .display-link { padding: 9px; }
  .display-link svg { width: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login-card { width: min(100%, 430px); padding: 34px; border-top: 5px solid var(--green); border-radius: 8px; background: var(--paper); box-shadow: 0 24px 70px rgba(0,0,0,.24); }
.login-card .school-mark { width: 64px; }
.login-card h1 { margin: 14px 0 6px; font-family: Georgia, "Times New Roman", serif; font-size: 34px; letter-spacing: -.035em; }
.login-card > p { margin: 0 0 24px; color: var(--muted); line-height: 1.5; }
.login-card form { display: grid; gap: 16px; }
.login-card label { display: grid; gap: 7px; font-size: 14px; font-weight: 700; }
.login-card input { width: 100%; height: 46px; padding: 0 12px; border: 1.5px solid #c5c9ca; border-radius: 7px; background: white; }
.login-card a { display: inline-block; margin-top: 20px; color: var(--ink); font-weight: 700; }
.login-error,.login-success { margin: 16px 0; padding: 12px; border-radius: 6px; font-size: 14px; font-weight: 650; }
.login-error { color: #8f2929; background: #f9e5e3; }
.login-success { color: #1d6530; background: #e3f2e7; }
.admin-links { display: flex; justify-content: space-between; margin-top: 18px; }
.admin-links a { color: var(--ink); font-size: 14px; font-weight: 700; text-underline-offset: 3px; }
