:root {
  color-scheme: dark;
  --bg: oklch(0.18 0.045 282);
  --bg-2: oklch(0.25 0.072 286);
  --panel: oklch(0.985 0.01 285);
  --panel-2: oklch(0.94 0.018 285);
  --ink: oklch(0.18 0.035 282);
  --muted: oklch(0.43 0.035 282);
  --line: oklch(0.84 0.024 285);
  --primary: oklch(0.62 0.18 23);
  --primary-strong: oklch(0.52 0.17 23);
  --accent: oklch(0.78 0.14 78);
  --danger: oklch(0.55 0.19 28);
  --radius: 10px;
  --shadow: 0 24px 70px oklch(0 0 0 / 0.28);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 50% -10%, oklch(0.39 0.105 302), transparent 27rem),
    radial-gradient(circle at 85% 8%, oklch(0.46 0.13 23 / 0.58), transparent 18rem),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  color: white;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 46px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 15px;
  background: var(--primary);
  color: white;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}

button:hover {
  background: var(--primary-strong);
  box-shadow: 0 12px 28px oklch(0.12 0.05 23 / 0.28);
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  background: white;
  color: var(--ink);
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.45;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-panel,
.bottom-sheet {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login-panel {
  width: 100%;
  display: grid;
  gap: 14px;
  padding: 24px 20px 20px;
}

.login-panel h1,
.app-header h1 {
  margin: 0;
  line-height: 1.1;
}

.login-panel p,
.sheet-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.label {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.app-view {
  display: grid;
  gap: 14px;
  padding-bottom: 26px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-top: 6px;
}

.quiet-button {
  background: oklch(1 0 0 / 0.12);
  border: 1px solid oklch(1 0 0 / 0.22);
  color: white;
}

.quiet-button:hover {
  background: oklch(1 0 0 / 0.2);
  box-shadow: none;
}

.course-dashboard {
  display: grid;
  gap: 13px;
  padding: 15px;
  border-radius: 20px;
  background:
    linear-gradient(135deg, oklch(0.985 0.012 285), oklch(0.925 0.025 286));
  color: var(--ink);
  border: 1px solid oklch(1 0 0 / 0.24);
  box-shadow: var(--shadow);
}

.course-dashboard .label {
  color: var(--primary-strong);
}

.course-dashboard-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.course-dashboard-head h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
  text-wrap: balance;
}

.course-progress {
  min-width: 72px;
  min-height: 54px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 8px 10px;
  border-radius: 14px;
  background: oklch(0.18 0.04 282);
  color: white;
  border: 1px solid oklch(1 0 0 / 0.16);
}

.course-progress strong {
  font-size: 23px;
  line-height: 1;
}

.course-progress span {
  color: oklch(0.86 0.028 285);
  font-size: 12px;
  font-weight: 800;
}

.course-list {
  display: grid;
  gap: 9px;
}

.course-slot {
  position: relative;
  min-height: 84px;
  background: oklch(1 0 0);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: none;
  overflow: hidden;
  transition: transform 160ms var(--ease), border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}

.course-slot::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, oklch(0.78 0.14 78 / 0.14));
  opacity: 0;
  transition: opacity 180ms var(--ease);
}

.course-slot.selected {
  border-color: var(--primary);
  box-shadow: 0 16px 34px oklch(0.18 0.045 282 / 0.16);
  transform: translateY(-1px);
}

.course-slot.selected::after,
.course-slot.filled::after {
  opacity: 1;
}

.course-slot.filled {
  background:
    linear-gradient(135deg, oklch(1 0 0), oklch(0.965 0.025 78));
}

.course-pick {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 84px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  padding: 12px 72px 12px 12px;
  text-align: left;
  background: transparent;
  color: inherit;
  border-radius: inherit;
  box-shadow: none;
}

.course-pick:hover {
  background: oklch(1 0 0 / 0.34);
  box-shadow: none;
}

.course-step {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: oklch(0.94 0.018 285);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.course-slot.filled .course-step {
  background: var(--accent);
  color: var(--ink);
  box-shadow: 0 0 0 6px oklch(0.78 0.14 78 / 0.18);
}

.course-meta {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.course-name {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
}

.course-slot strong {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 20px;
  line-height: 1.24;
  color: var(--ink);
}

.course-slot.empty strong {
  color: oklch(0.52 0.035 282);
}

.course-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.25;
}

.delete-item {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  background: oklch(0.97 0.02 28);
  color: oklch(0.43 0.14 28);
  border: 1px solid oklch(0.82 0.08 28);
  box-shadow: none;
  font-size: 12px;
  font-weight: 900;
}

.delete-item:hover {
  background: oklch(0.92 0.045 28);
  color: oklch(0.34 0.14 28);
  box-shadow: 0 10px 18px oklch(0.45 0.16 28 / 0.16);
}

.arcade-stage {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: 18px;
  background: oklch(0.22 0.06 286);
  border: 1px solid oklch(1 0 0 / 0.13);
  box-shadow: var(--shadow);
}

.arcade-display {
  min-height: 136px;
  display: grid;
  place-items: center;
  padding: 18px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 50% 20%, oklch(0.62 0.17 23 / 0.5), transparent 9rem),
    oklch(0.15 0.045 286);
  color: white;
  font-size: 28px;
  font-weight: 900;
  text-align: center;
  line-height: 1.2;
}

.arcade-display.is-rolling {
  animation: pulse 320ms ease-out infinite alternate;
}

.arcade-display.is-revealed {
  animation: reveal-pop 520ms var(--ease);
}

.item-selector {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.item-pill {
  flex: 0 0 auto;
  min-height: 38px;
  background: oklch(1 0 0 / 0.12);
  border: 1px solid oklch(1 0 0 / 0.18);
  color: white;
}

.item-pill.selected {
  background: var(--accent);
  color: var(--ink);
}

.draw-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.draw-button {
  grid-column: span 2;
  min-height: 56px;
  font-size: 18px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.42);
  z-index: 20;
}

.bottom-sheet {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 560px);
  max-height: min(78vh, 720px);
  overflow: auto;
  padding: 16px;
  z-index: 30;
}

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

.sheet-close-button {
  min-width: 70px;
  background: oklch(0.61 0.2 28);
}

.sheet-header h2,
.line-group h3 {
  margin: 0;
}

.line-groups,
.candidate-list {
  display: grid;
  gap: 10px;
}

.line-toolbar {
  position: sticky;
  top: -16px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 -2px 12px;
  padding: 10px;
  border-radius: 14px;
  background: oklch(0.985 0.01 285 / 0.96);
  border: 1px solid var(--line);
}

.line-toolbar span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.line-toolbar div,
.line-group-actions {
  display: flex;
  gap: 6px;
}

.mini-button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  box-shadow: none;
  font-size: 12px;
  font-weight: 900;
}

.mini-button:hover {
  background: oklch(0.26 0.045 282);
  box-shadow: none;
}

.quiet-mini-button {
  background: oklch(0.94 0.018 285);
  color: var(--ink);
  border: 1px solid var(--line);
}

.quiet-mini-button:hover {
  background: oklch(0.9 0.02 285);
  box-shadow: none;
}

.line-group {
  display: grid;
  gap: 12px;
  padding: 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.line-group-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.line-group-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.line-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.candidate-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
}

.line-card {
  position: relative;
  min-height: 48px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border-radius: 13px;
  background: oklch(1 0 0);
  color: var(--ink);
  border: 1px solid oklch(0.86 0.02 285);
  cursor: pointer;
  transition: transform 160ms var(--ease), border-color 160ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}

.line-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--line-color), white 28%);
  box-shadow: 0 10px 22px oklch(0.18 0.04 282 / 0.1);
}

.line-card:has(.line-toggle:checked) {
  background: color-mix(in srgb, var(--line-color), white 88%);
  border-color: color-mix(in srgb, var(--line-color), white 18%);
}

.line-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.line-swatch {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--line-color);
  color: white;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--line-color), transparent 82%);
  font-size: 13px;
  font-weight: 950;
  line-height: 1;
}

.line-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
}

.line-check {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: oklch(0.91 0.018 285);
  color: transparent;
  font-size: 13px;
  font-weight: 900;
}

.line-card:has(.line-toggle:checked) .line-check {
  background: var(--line-color);
  color: white;
}

#saveLinesButton {
  position: sticky;
  bottom: -16px;
  width: 100%;
  min-height: 52px;
  margin-top: 12px;
  border-radius: 14px;
  box-shadow: 0 -12px 26px oklch(0.985 0.01 285 / 0.82);
}

.candidate-chip {
  justify-content: space-between;
  background: var(--panel-2);
  color: var(--ink);
}

.candidate-list {
  margin-bottom: 16px;
}

.candidate-editor-form {
  gap: 12px;
}

.form-grid {
  display: grid;
  gap: 10px;
}

.toast,
.form-error {
  color: oklch(0.71 0.18 28);
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 18px;
  right: 18px;
  bottom: 18px;
  max-width: 520px;
  margin: 0 auto;
  padding: 13px 14px;
  background: var(--panel);
  color: var(--danger);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 40;
}

.prep-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
  background: oklch(1 0 0 / 0.08);
  border: 1px solid oklch(1 0 0 / 0.14);
}

.prep-panel-head {
  display: grid;
  gap: 7px;
}

.prep-panel-head h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.prep-panel-head p {
  margin: 0;
  max-width: 44ch;
  color: oklch(0.88 0.018 285);
  line-height: 1.45;
}

.management-bar {
  display: grid;
  gap: 10px;
}

.prep-action {
  position: relative;
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 13px 14px 13px 46px;
  text-align: left;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}

.prep-action::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  box-shadow: 0 0 0 5px oklch(0.78 0.14 78 / 0.18);
}

.prep-action:hover {
  background: oklch(0.965 0.014 285);
  box-shadow: 0 14px 32px oklch(0 0 0 / 0.18);
}

.prep-action-title {
  display: block;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.25;
}

.prep-action-copy {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.prep-action.danger-button {
  background: oklch(0.96 0.024 28);
  border-color: oklch(0.78 0.09 28);
  color: oklch(0.34 0.1 28);
}

.prep-action.danger-button::before {
  background: var(--danger);
  box-shadow: 0 0 0 5px oklch(0.55 0.19 28 / 0.16);
}

.prep-action.danger-button .prep-action-copy {
  color: oklch(0.43 0.075 28);
}

@keyframes pulse {
  from {
    transform: scale(1);
    filter: brightness(1);
  }
  to {
    transform: scale(1.015);
    filter: brightness(1.18);
  }
}

@keyframes reveal-pop {
  0% {
    transform: scale(0.92);
  }
  65% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@media (min-width: 620px) {
  .course-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .management-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .line-grid {
    grid-template-columns: 1fr;
  }

  .line-toolbar,
  .line-group-head {
    align-items: stretch;
    flex-direction: column;
  }
}

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