:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.14);
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --accent: #f97316;
  --red: #ff315b;
  --orange: #f59e0b;
  --green: #10b981;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: 34px;
  color: var(--ink);
  background: #f6f8fc;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.icp-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 12;
  display: grid;
  min-height: 34px;
  place-items: center;
  padding: 6px 16px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.94);
  font-size: 12px;
}

.icp-footer a {
  color: var(--muted);
  text-decoration: none;
}

.icp-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.icp-footer-display {
  background: rgba(255, 255, 255, 0.78);
}

.admin-page {
  background: #f6f8fc;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px 24px 58px;
  background:
    radial-gradient(circle at 50% 20%, rgba(249, 115, 22, 0.14), transparent 34%),
    #f6f8fc;
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  display: grid;
  gap: 20px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 26px 90px rgba(15, 23, 42, 0.12);
}

.login-card p,
.login-card h1 {
  margin: 0;
}

.login-card p {
  color: var(--muted);
}

.login-card h1 {
  margin-top: 8px;
  font-size: 34px;
}

.login-error {
  margin: 0;
  color: #be123c;
  line-height: 1.5;
}

.admin-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - 34px);
}

.sidebar {
  padding: 28px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.brand {
  display: grid;
  gap: 8px;
  margin-bottom: 26px;
}

.brand span,
.round-form header p,
.background-box p,
.control-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.brand strong {
  font-size: 28px;
}

.primary-btn,
.ghost-btn,
.copy-row button,
.timer-actions button,
.score-actions button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.ghost-btn {
  margin-left: 12px;
  color: var(--ink);
  background: #e2e8f0;
}

.round-list {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.round-row {
  position: relative;
}

.round-item {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 16px 48px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
}

.round-item small {
  color: var(--muted);
}

.round-name {
  min-width: 0;
}

.delete-round {
  position: absolute;
  top: 14px;
  right: 12px;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.delete-round:hover {
  border-color: rgba(255, 49, 91, 0.5);
  color: #be123c;
  background: rgba(255, 49, 91, 0.18);
}

.round-row.is-active .round-item {
  border-color: var(--accent);
}

.panel {
  padding: 34px;
}

.empty,
.round-form {
  max-width: 1040px;
}

.empty {
  display: inline-grid;
  min-height: 48px;
  min-width: 180px;
  place-items: center;
  padding: 0 18px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.round-form {
  display: grid;
  gap: 24px;
}

.round-form header,
.control-header,
.background-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.round-form h1,
.background-box h2,
.control-header h1,
.control-player h2 {
  margin: 0;
}

.form-grid,
.players-editor,
.links,
.players-control {
  display: grid;
  gap: 16px;
}

.form-grid,
.players-editor {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
}

input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

.background-box {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.background-preview {
  position: relative;
  overflow: hidden;
  width: min(360px, 44vw);
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: #eef4ff;
  background-size: cover;
  background-position: center;
}

.background-preview::after {
  display: none;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
  padding: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(226, 232, 240, 0.88)),
    radial-gradient(circle at center, rgba(249, 115, 22, 0.14), transparent 58%);
}

.preview-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-score-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  align-items: center;
}

.preview-player {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 7px 4px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.86);
  text-align: center;
}

.preview-player span {
  overflow: hidden;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-player strong,
.preview-clock {
  font-family: "Arial Black", Impact, sans-serif;
  line-height: 1;
}

.preview-player strong {
  font-size: 28px;
}

.preview-player.red strong {
  color: var(--red);
}

.preview-player.orange strong {
  color: var(--orange);
}

.preview-player.green strong {
  color: var(--green);
}

.preview-clock {
  color: var(--red);
  font-size: 22px;
  text-align: center;
}

.sync-feedback {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  color: #166534;
  background: #f0fdf4;
  line-height: 1.6;
  word-break: break-all;
}

.copy-row {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 10px;
}

.copy-row button {
  color: var(--ink);
  background: #e2e8f0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.32);
}

.confirm-modal {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.18);
}

.confirm-modal h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.confirm-modal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.danger-btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  color: #fff;
  background: var(--red);
  font-weight: 700;
}

.deleted-state {
  display: grid;
  min-height: 100vh;
  place-items: center;
  color: var(--muted);
  background: #f6f8fc;
  font-size: 22px;
}

.display-page {
  overflow: hidden;
  background-color: #eef4ff;
  background-size: cover;
  background-position: center;
}

.display-page::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(226, 232, 240, 0.88)),
    radial-gradient(circle at center, rgba(249, 115, 22, 0.14), transparent 58%);
  pointer-events: none;
}

.display-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 34px);
  padding: 4vh 4vw 5vh;
}

.display-header {
  text-align: center;
}

.display-header span {
  display: inline-grid;
  min-width: 112px;
  min-height: 34px;
  place-items: center;
  border: 1px solid rgba(249, 115, 22, 0.28);
  border-radius: 999px;
  color: #9a3412;
  background: rgba(255, 247, 237, 0.86);
}

.display-header h1 {
  margin: 18px 0 0;
  font-size: clamp(36px, 5vw, 78px);
}

.score-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2vw;
  align-items: center;
}

.player-card {
  display: grid;
  gap: 3vh;
  justify-items: center;
  padding: 3vh 2vw;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.10);
}

.player-card h2 {
  margin: 0;
  font-size: clamp(26px, 3.1vw, 54px);
}

.score {
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(92px, 15vw, 260px);
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow: 0 0 20px currentColor;
}

.player-card.red {
  color: var(--red);
}

.player-card.orange {
  color: var(--orange);
}

.player-card.green {
  color: var(--green);
}

.time-board {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.main-clock {
  color: var(--red);
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(48px, 8vw, 140px);
  line-height: 1;
  text-shadow: 0 0 18px currentColor;
}

.shot-clock {
  color: var(--green);
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(74px, 11vw, 180px);
  line-height: 1;
  text-shadow: 0 0 20px currentColor;
}

.control-page {
  background: #f6f8fc;
}

.control-shell {
  display: grid;
  gap: 22px;
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 28px 52px;
}

.control-header {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.control-header strong {
  color: var(--red);
  font-size: 48px;
  font-family: "Arial Black", Impact, sans-serif;
}

.timer-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.timer-actions button {
  color: var(--ink);
  background: #e2e8f0;
}

.control-player {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.control-player strong {
  display: block;
  margin-top: 8px;
  color: var(--accent);
  font-size: 40px;
}

.score-actions {
  display: grid;
  grid-template-columns: repeat(4, 72px);
  gap: 10px;
}

.score-actions button {
  color: var(--ink);
  background: var(--panel-2);
}

.score-actions button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.toast-host {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: min(320px, calc(100vw - 32px));
}

.toast {
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  color: #166534;
  background: #f0fdf4;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.14);
  font-size: 14px;
  font-weight: 700;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.error {
  border-color: #fecaca;
  color: #991b1b;
  background: #fef2f2;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(8px);
}

@media (max-width: 860px) {
  .admin-shell,
  .form-grid,
  .players-editor,
  .control-player {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .score-board {
    grid-template-columns: 1fr;
    align-content: center;
  }

  .display-shell {
    min-height: calc(100svh - 34px);
  }

  .background-box,
  .round-form header,
  .control-header {
    align-items: stretch;
    flex-direction: column;
  }

  .background-preview {
    width: 100%;
  }

  .score-actions {
    grid-template-columns: repeat(4, 1fr);
  }
}
