:root {
  color-scheme: light;
  --ink: #18201f;
  --muted: #60716d;
  --line: #dbe5df;
  --panel: #ffffff;
  --surface: #f4f7f2;
  --accent: #0f766e;
  --accent-dark: #0b504b;
  --gold: #d89522;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(24, 32, 31, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(125deg, rgba(15, 118, 110, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(216, 149, 34, 0.14), transparent 30%),
    var(--surface);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.8rem);
  line-height: 0.94;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

h3 {
  margin-bottom: 8px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  min-width: 280px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.nav-link {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}

.nav-link:hover {
  border-color: #cbd8d2;
  background: #fff;
}

.admin-session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 10px 12px;
}

.mode-button,
.ghost-button,
.primary-button,
.danger-button,
.file-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 750;
}

.mode-button {
  background: transparent;
  color: var(--muted);
}

.mode-button.active {
  background: var(--ink);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.player-grid,
.admin-grid {
  display: grid;
  gap: 18px;
}

.player-grid {
  grid-template-columns: minmax(0, 1fr) 330px;
}

.admin-grid {
  grid-template-columns: 430px minmax(0, 1fr);
}

.stage-panel,
.side-panel,
.stage-form-panel,
.stage-list-panel,
.access-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.stage-panel,
.stage-form-panel,
.stage-list-panel,
.access-panel {
  padding: 22px;
}

.access-panel {
  width: min(520px, 100%);
  margin: 0 auto;
}

.side-panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header.compact {
  align-items: center;
}

.badge {
  flex: 0 0 auto;
  border: 1px solid #cfd9d4;
  border-radius: 999px;
  padding: 7px 10px;
  background: #f8faf8;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.player-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.timer-badge {
  background: var(--ink);
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.full-button {
  width: 100%;
  margin-top: 18px;
}

.finish-panel {
  text-align: center;
}

.finish-panel h2 {
  font-size: 2rem;
}

.finish-summary {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 750;
}

.photo-frame {
  display: grid;
  place-items: center;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eaf0ed;
}

.photo-frame img {
  width: 100%;
  height: 100%;
  max-height: 62vh;
  object-fit: contain;
  background: #111;
}

.empty-state,
.empty-box {
  color: var(--muted);
  text-align: center;
}

.empty-state {
  display: grid;
  gap: 8px;
  padding: 28px;
}

.empty-box {
  border: 1px dashed #c7d5cf;
  border-radius: 8px;
  padding: 22px;
}

.stage-details {
  margin-top: 18px;
  padding: 16px;
  border-left: 4px solid var(--gold);
  background: #fff9ec;
  border-radius: 0 8px 8px 0;
}

.stage-details p {
  margin-bottom: 0;
  color: var(--muted);
}

.hidden {
  display: none;
}

.actions,
.import-export,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button,
.file-button {
  border-color: #cbd8d2;
  background: #fff;
  color: var(--ink);
}

.danger-button {
  border-color: rgba(180, 35, 24, 0.28);
  background: #fff4f2;
  color: var(--danger);
}

.status-text {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.status-text.success {
  color: var(--accent);
}

.status-text.error {
  color: var(--danger);
}

.help-box {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.help-box summary {
  min-height: 44px;
  padding: 12px 14px;
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 800;
}

.help-content {
  padding: 0 14px 14px;
  color: var(--muted);
}

.help-content p,
.help-content ol {
  margin-bottom: 12px;
}

.help-content h3 {
  margin: 12px 0 6px;
  color: var(--ink);
  font-size: 1rem;
}

.help-content ol {
  padding-left: 20px;
}

.help-content li {
  margin-bottom: 6px;
}

.results-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.public-rally-list {
  display: grid;
  gap: 10px;
}

.public-rally-button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  color: var(--ink);
  text-align: left;
}

.public-rally-button span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.results-box {
  margin-top: 14px;
}

.results-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.results-list li {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
}

.results-list li span:last-child {
  color: var(--accent-dark);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.progress-list,
.admin-stage-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.progress-list {
  display: grid;
  gap: 10px;
}

.progress-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.progress-list li.current {
  border-color: rgba(15, 118, 110, 0.4);
  color: var(--ink);
  font-weight: 800;
}

.progress-list li.done {
  background: #edf8f5;
  color: var(--accent-dark);
}

.stage-form {
  display: grid;
  gap: 16px;
}

.stage-editor {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.muted-line {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 750;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cbd8d2;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
}

textarea {
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.align-end {
  align-self: end;
}

.admin-stage-list {
  display: grid;
  gap: 12px;
}

.rally-list-wrap {
  margin-top: 18px;
}

.rally-list {
  display: grid;
  gap: 10px;
}

.rally-list-button {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  color: var(--ink);
  text-align: left;
}

.rally-list-button.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: #edf8f5;
}

.rally-list-button span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.creator-admin-panel {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.password-form {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.creator-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.creator-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.creator-card span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inline-check input {
  width: auto;
}

.admin-stage-card {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 88px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-stage-card img {
  width: 88px;
  height: 68px;
  border-radius: 6px;
  object-fit: cover;
  background: #d7e0dc;
}

.admin-stage-card strong,
.admin-stage-card span {
  display: block;
}

.admin-stage-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.stage-card-actions {
  display: grid;
  grid-template-columns: repeat(4, 38px);
  gap: 6px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid #efc5bf;
  border-radius: 8px;
  background: #fff7f6;
  color: var(--danger);
  font-size: 1.1rem;
  line-height: 1;
}

.move-up-button,
.move-down-button,
.edit-stage-button {
  border-color: #cbd8d2;
  background: #fff;
  color: var(--ink);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.file-button {
  display: inline-grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

@media (max-width: 900px) {
  .topbar,
  .player-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .mode-switch {
    min-width: 0;
    width: 100%;
  }

  .photo-frame {
    min-height: 300px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 16px 0;
  }

  .stage-panel,
  .stage-form-panel,
  .stage-list-panel,
  .side-panel {
    padding: 14px;
  }

  .form-row,
  .admin-stage-card {
    grid-template-columns: 1fr;
  }

  .admin-stage-card img {
    width: 100%;
    height: 150px;
  }
}
