/* SPDX-License-Identifier: GPL-2.0-or-later */
:root {
  --ink: #17211b;
  --muted: #69726c;
  --paper: #f4f3ec;
  --card: #fffef9;
  --line: #dcded6;
  --green: #146c43;
  --green-soft: #dff1e7;
  --lime: #b8e850;
  --red: #b14638;
  --amber-soft: #fff0c7;
  --navy: #1c2e28;
  --shadow: 0 16px 45px rgba(34, 45, 38, 0.08);
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", "Hiragino Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 2%, rgba(184, 232, 80, 0.2), transparent 24rem),
    linear-gradient(180deg, #f8f7f1 0, var(--paper) 32rem);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="range"],
input[type="checkbox"] {
  cursor: pointer;
}

.page-shell {
  width: min(1540px, calc(100% - 40px));
  margin: 0 auto;
  padding: 42px 0 64px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  min-height: 150px;
  padding: 6px 6px 30px;
}

.section-label,
.summary-label {
  margin: 0;
  color: var(--green);
  font-family: "DM Mono", monospace;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 8px 0 6px;
  font-size: clamp(2rem, 4vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 1;
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(290px, 1fr) minmax(250px, 0.8fr) minmax(230px, 0.7fr);
  gap: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  color: white;
  background: var(--navy);
  box-shadow: var(--shadow);
}

.clock-block,
.settings-block {
  min-height: 142px;
  padding: 24px 28px;
}

.clock-block,
.settings-block {
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.control-panel .section-label,
.control-panel .field-label {
  color: #aebbb4;
}

.clock-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.elapsed-input {
  width: 138px;
  padding: 0;
  border: 0;
  outline: 0;
  color: white;
  background: transparent;
  font-family: "DM Mono", monospace;
  font-size: 2.35rem;
  font-weight: 500;
  letter-spacing: -0.06em;
}

.elapsed-input:focus {
  box-shadow: 0 2px 0 var(--lime);
}

.play-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: white;
  background: rgba(255, 255, 255, 0.06);
  transition: 150ms ease;
}

.play-button:hover {
  border-color: var(--lime);
  color: var(--navy);
  background: var(--lime);
}

.play-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  margin-left: auto;
  padding: 0 13px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.play-icon {
  color: var(--lime);
  font-size: 0.67rem;
}

.play-button:hover .play-icon,
.play-button.playing .play-icon {
  color: var(--navy);
}

.play-button.playing {
  border-color: var(--lime);
  color: var(--navy);
  background: var(--lime);
}

.wall-clock {
  margin-top: 7px;
  color: #aebbb4;
  font-family: "DM Mono", monospace;
  font-size: 0.73rem;
}

.settings-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.field-label {
  margin-bottom: 7px;
  font-size: 0.72rem;
}

.settings-block select {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 9px;
  color: white;
  background: #2b3c36;
  outline: none;
  font-size: 0.84rem;
}

.settings-block select:focus {
  border-color: var(--lime);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 15px;
  color: #d9e0dc;
  font-size: 0.78rem;
  cursor: pointer;
}

.toggle-row[hidden] {
  display: none;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
}

.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 99px;
  background: #52605b;
  transition: 150ms ease;
}

.toggle-track::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  content: "";
  transition: 150ms ease;
}

.toggle-row input:checked + .toggle-track {
  background: var(--lime);
}

.toggle-row input:checked + .toggle-track::after {
  left: 19px;
  background: var(--navy);
}

.timeline-wrap {
  grid-column: 1 / -1;
  padding: 18px 28px 22px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.timeline-labels {
  position: relative;
  height: 12px;
  margin-bottom: 8px;
  color: #91a098;
  font-family: "DM Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

.timeline-labels span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.timeline-labels span:first-child {
  left: 0;
  transform: none;
}

.range-shell {
  position: relative;
}

input[type="range"] {
  width: 100%;
  height: 5px;
  margin: 0;
  border-radius: 99px;
  appearance: none;
  background: linear-gradient(to right, var(--lime) var(--range-progress, 0%), #52605b var(--range-progress, 0%));
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  position: relative;
  z-index: 4;
  width: 19px;
  height: 19px;
  border: 4px solid var(--navy);
  border-radius: 50%;
  appearance: none;
  background: var(--lime);
  box-shadow: 0 0 0 1px var(--lime);
}

input[type="range"]::-moz-range-thumb {
  position: relative;
  z-index: 4;
  width: 11px;
  height: 11px;
  border: 4px solid var(--navy);
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 0 1px var(--lime);
}

.timeline-mark {
  position: absolute;
  top: -4px;
  z-index: 1;
  width: 1px;
  height: 13px;
  background: rgba(255, 255, 255, 0.45);
  pointer-events: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: 0.65fr 0.65fr 0.8fr 1.4fr;
  gap: 12px;
  margin: 18px 0 36px;
}

.summary-card {
  min-height: 120px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 254, 249, 0.78);
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-family: "DM Mono", monospace;
  font-size: 2rem;
  letter-spacing: -0.06em;
}

.summary-card small {
  color: var(--muted);
  font-size: 0.7rem;
}

.summary-card.accent {
  border-color: #b8d7c3;
  background: var(--green-soft);
}

.summary-card.pending-card.has-pending {
  border-color: #ead09a;
  background: var(--amber-soft);
}

.scoreboard-section {
  min-width: 0;
}

.table-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
  padding: 0 4px;
}

.table-toolbar h2 {
  margin: 4px 0 0;
  font-size: 1.65rem;
  letter-spacing: -0.04em;
}

.toolbar-actions,
.search-box {
  display: flex;
  align-items: center;
}

.toolbar-actions {
  gap: 20px;
}

.search-box {
  gap: 8px;
  width: min(290px, 30vw);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.search-box span {
  color: var(--muted);
  font-size: 1.2rem;
}

.search-box input {
  width: 100%;
  height: 38px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 0.78rem;
}

.table-card {
  position: relative;
  min-height: 280px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.table-scroll {
  max-height: min(68vh, 820px);
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1240px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.78rem;
}

th,
td {
  height: 58px;
  padding: 7px 8px;
  border-right: 1px solid #e7e8e2;
  border-bottom: 1px solid #e7e8e2;
  text-align: center;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 72px;
  color: #52605a;
  background: #f0f1eb;
  font-size: 0.67rem;
  font-weight: 600;
  text-transform: uppercase;
}

th:last-child,
td:last-child {
  border-right: 0;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background-color: #fafbf5;
}

.rank-col {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 58px;
  min-width: 58px;
  color: var(--muted);
  background: var(--card);
  font-family: "DM Mono", monospace;
  font-size: 0.82rem;
}

thead .rank-col {
  z-index: 5;
  background: #f0f1eb;
}

.team-col {
  position: sticky;
  left: 58px;
  z-index: 2;
  width: 250px;
  min-width: 250px;
  padding-left: 16px;
  background: var(--card);
  text-align: left;
  box-shadow: 8px 0 14px -14px rgba(24, 36, 29, 0.45);
}

thead .team-col {
  z-index: 5;
  background: #f0f1eb;
}

.team-name {
  overflow: hidden;
  font-size: 0.84rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-affiliation {
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.65rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-col {
  width: 66px;
  min-width: 66px;
  font-family: "DM Mono", monospace;
  font-weight: 500;
}

.time-col {
  width: 76px;
  min-width: 76px;
  color: #4c5b54;
  font-family: "DM Mono", monospace;
}

.problem-heading {
  width: 69px;
  min-width: 69px;
}

.loading-state,
.error-state {
  display: grid;
  min-height: 280px;
  place-content: center;
  justify-items: center;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.loading-state[hidden],
.error-state[hidden],
.table-scroll[hidden] {
  display: none;
}

.error-state strong {
  color: var(--red);
}

.error-state p {
  max-width: 580px;
  margin: 8px 0;
  font-size: 0.8rem;
}

.error-state code {
  margin-top: 12px;
  padding: 9px 13px;
  border-radius: 7px;
  color: var(--ink);
  background: #eceee7;
}

.loader {
  width: 26px;
  height: 26px;
  margin-bottom: 14px;
  border: 3px solid #d8ddd7;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.table-note {
  margin: 11px 4px 0;
  color: var(--muted);
  font-size: 0.67rem;
}

@media (max-width: 980px) {
  .control-panel {
    grid-template-columns: 1fr 1fr;
  }

  .settings-block {
    border-right: 0;
  }

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

  .table-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .search-box {
    width: min(350px, 52vw);
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 1540px);
    padding-top: 20px;
  }

  .hero {
    min-height: 120px;
    padding: 4px 2px 20px;
  }

  .control-panel {
    grid-template-columns: 1fr;
    border-radius: 16px;
  }

  .clock-block,
  .settings-block {
    min-height: auto;
    padding: 20px;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .elapsed-input {
    width: 122px;
    font-size: 2rem;
  }

  .timeline-wrap {
    grid-column: auto;
    padding: 18px 20px 20px;
  }

  .summary-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin-bottom: 28px;
  }

  .summary-card {
    min-height: 100px;
    padding: 15px 13px;
  }

  .summary-card strong {
    font-size: 1.55rem;
  }

  .toolbar-actions {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .search-box {
    width: 100%;
  }

  .team-col {
    width: 190px;
    min-width: 190px;
  }

  table {
    min-width: 1160px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
