:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --panel: #ffffff;
  --text: #15171a;
  --muted: #626a73;
  --line: #dfe3e8;
  --blue: #2563eb;
  --green: #15803d;
  --red: #dc2626;
  --amber: #b45309;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

button.danger {
  border-color: var(--red);
  color: var(--red);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
  font-size: 16px;
}

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.mobile {
  width: min(680px, 100%);
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions select {
  width: auto;
  min-width: 150px;
  max-width: 220px;
}

.title {
  font-size: 20px;
  font-weight: 750;
}

.subtle {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

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

.panel h2,
.panel h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.tabs button {
  min-height: 48px;
  padding: 8px 6px;
}

.tabs button.active {
  border-color: var(--blue);
  color: var(--blue);
  font-weight: 700;
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

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

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  background: #eef2ff;
  color: #3730a3;
}

.badge.green {
  background: #dcfce7;
  color: var(--green);
}

.badge.red {
  background: #fee2e2;
  color: var(--red);
}

.badge.amber {
  background: #fef3c7;
  color: var(--amber);
}

.role-text {
  white-space: pre-wrap;
  line-height: 1.6;
}

.panel.done {
  opacity: 0.55;
}

.punishment-top {
  border-color: var(--red);
}

.secret {
  filter: blur(8px);
  user-select: none;
}

.secret.revealed {
  filter: none;
}

.status {
  min-height: 22px;
  color: var(--muted);
}

.admin-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 12px;
}

.sidebar button {
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
}

.sidebar-group {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 4px 6px;
}

.sidebar-group:first-child {
  margin-top: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 14px;
}

.field {
  display: grid;
  gap: 4px;
  align-content: start;
}

.field > label {
  font-size: 12px;
  color: var(--muted);
}

.field.full {
  grid-column: 1 / -1;
}

.field.check {
  grid-auto-flow: column;
  grid-template-columns: auto 1fr;
  justify-content: start;
  align-items: center;
  gap: 8px;
}

.field.check input {
  width: auto;
}

.field.check > label {
  font-size: 13px;
  color: var(--text);
}

.checkset {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.checkset label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}

.checkset input {
  width: auto;
}

.dur-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dur-row input {
  width: 90px;
}

.dt-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.dt-row input {
  flex: 1;
}

.dur-sep {
  color: var(--muted);
  font-size: 13px;
}

/* Game rank -> score editor rows */
.rank-rows {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rank-label {
  min-width: 42px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.rank-row input {
  width: 120px;
}

.rank-row [data-rank-del] {
  min-height: 36px;
  padding: 4px 10px;
}

/* Schedule run-order cards */
.order-list {
  display: grid;
  gap: 10px;
}

.order-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}

.order-pos {
  flex: none;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-weight: 750;
  font-size: 15px;
}

.order-body {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.order-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.order-title {
  font-size: 16px;
  font-weight: 700;
}

.order-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  color: var(--muted);
  font-size: 13px;
}

.order-metaitem b {
  color: var(--text);
  font-weight: 600;
}

.order-arrow {
  color: var(--muted);
}

.order-buffer input {
  width: 84px;
}

.order-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.order-actions button {
  min-width: 46px;
}

/* Two-panel drag & drop order editor */
.order-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.order-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 8px;
}

.order-drop {
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 140px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
}

.order-drop.drag-over {
  border-color: var(--blue);
  background: #eff6ff;
}

.order-card[draggable="true"] {
  cursor: grab;
}

.order-card.dragging {
  opacity: 0.4;
}

.order-empty {
  padding: 24px 12px;
  text-align: center;
}

/* Schedule map (Leaflet) */
.schedule-map {
  height: 480px;
  border-radius: 10px;
  overflow: hidden;
  background: #e8ecef;
}

.map-pin {
  background: var(--blue);
  color: #fff;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

@media (max-width: 760px) {
  .order-cols {
    grid-template-columns: 1fr;
  }
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.form-host {
  margin-bottom: 12px;
}

.url-box {
  word-break: break-all;
  font-size: 13px;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 650;
}

/* Space out adjacent action buttons in tables so labels don't run together */
td button {
  margin: 3px 6px 3px 0;
}

.toolbar {
  gap: 12px;
}

@media (max-width: 760px) {
  .app {
    padding: 12px;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  /* Participant: pin the nav to the bottom for one-handed use. */
  .app.mobile {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .app.mobile .topbar {
    padding-top: env(safe-area-inset-top);
  }

  .app.mobile .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    margin: 0;
    gap: 4px;
    grid-template-columns: repeat(6, 1fr);
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
  }

  .app.mobile .tabs button {
    border: 0;
    background: transparent;
    border-radius: 10px;
    min-height: 52px;
    padding: 6px 2px;
    font-size: 13px;
    color: var(--muted);
  }

  .app.mobile .tabs button.active {
    background: #eef2ff;
    color: var(--blue);
  }
}

