:root {
  --bg: #0d1223;
  --bg-2: #11192e;
  --panel-bg: rgba(17, 25, 46, 0.88);
  --panel-edge: rgba(255, 255, 255, 0.08);
  --primary: #85b7ff;
  --primary-strong: #4d88ff;
  --gold: #f5c76d;
  --gold-soft: rgba(245, 199, 109, 0.16);
  --danger: #f16f6f;
  --danger-soft: rgba(241, 111, 111, 0.16);
  --success: #7dd3a2;
  --text: #edf3ff;
  --muted: #a3b3d9;
  --shadow: 0 18px 40px rgba(9, 14, 24, 0.35);
  --row-h: 48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Apple SD Gothic Neo", sans-serif;
  background: linear-gradient(180deg, #0a1120 0%, #0d1223 100%);
  color: var(--text);
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button, input, textarea {
  font: inherit;
}

button { cursor: pointer; }

.app-shell[hidden],
.login-screen[hidden] {
  display: none;
}

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-panel {
  width: min(100%, 420px);
  padding: 2rem;
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.login-icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  border-radius: 12px;
  background: linear-gradient(135deg, #7dd4ff, #8d87ff 55%, #f5c76d);
  font-size: 1.5rem;
}

.login-panel h1 {
  margin: 0 0 1.5rem;
  font-size: 1.35rem;
}

.login-panel label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.login-form-row {
  display: flex;
  gap: 0.5rem;
}

.login-form-row input {
  min-width: 0;
  flex: 1;
  padding: 0.7rem 0.8rem;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 10px;
  background: rgba(0,0,0,0.2);
  color: var(--text);
}

.login-submit {
  padding: 0.7rem 1rem;
  border: 0;
  border-radius: 10px;
  background: var(--primary-strong);
  color: #fff;
  font-weight: 700;
}

.login-error {
  min-height: 1.3rem;
  margin: 0.6rem 0 0;
  color: #ff9a9a;
  font-size: 0.84rem;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: 0.8rem 1rem 0.7rem;
  gap: 0.8rem;
}

.app-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border: 1px solid var(--panel-edge);
  background: rgba(17, 25, 46, 0.8);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.brand-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 180px;
  font-weight: 700;
}

.group-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.38rem 0.7rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
}

.group-label {
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}

#group-code-select,
#group-select {
  min-width: 160px;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  font-weight: 600;
}

#group-code-select option,
#group-select option {
  color: #172033;
  background-color: #ffffff;
}

#group-code-select option:checked,
#group-select option:checked {
  color: #ffffff;
  background-color: #2563eb;
}

.brand-icon {
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #7dd4ff, #8d87ff 55%, #f5c76d);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
}

.progress-wrap {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.progress-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.progress-bar {
  position: relative;
  height: 0.7rem;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--primary));
  transition: width 0.2s ease;
}

.stat-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.stat-pill {
  min-width: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.05);
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-pill strong {
  color: var(--text);
  font-size: 0.95rem;
}

.action-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.top-btn, .action-btn, .mini-btn, .shortcut-btn, .preset-chip, .launch-btn {
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 12px;
  transition: 0.18s ease;
}

.top-btn {
  padding: 0.58rem 0.9rem;
  font-weight: 600;
}

.complete-draw-btn {
  margin: 0.5rem 0.8rem 0.8rem;
  min-height: 2.6rem;
  border: 1px solid rgba(125, 211, 162, 0.55);
  border-radius: 10px;
  background: var(--success);
  color: #102c1c;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.complete-draw-btn[hidden] {
  display: none;
}

.complete-draw-btn:disabled {
  cursor: default;
  opacity: 0.75;
}

#import-roster-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.top-btn:hover, .action-btn:hover, .mini-btn:hover, .shortcut-btn:hover, .preset-chip:hover, .launch-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(133,183,255,0.5);
}

.badge, .count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: rgba(133,183,255,0.18);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
}

.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(200px, 1.1fr) minmax(220px, 0.9fr) minmax(200px, 1.1fr);
  gap: 0.9rem;
}

.pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(17, 25, 46, 0.72);
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.8rem 0.9rem 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.pane-head h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
}

.plist {
  display: grid;
  grid-auto-rows: minmax(1.25rem, 1fr);
  gap: 0.06rem;
  padding: 0.45rem 0.5rem 0.6rem;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
}

.prow {
  --row-h: 48px;
  display: grid;
  grid-template-columns: 3.1rem 1fr auto;
  align-items: center;
  gap: 0.55rem;
  min-height: 0;
  height: 100%;
  padding: 0 0.55rem;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(105, 150, 255, 0.08);
  color: var(--text);
  transition: 0.2s ease;
}

.prow:hover {
  border-color: rgba(133,183,255,0.4);
}

.prow.selected {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(245, 199, 109, 0.6);
}

.prow.assigned {
  background: rgba(245, 199, 109, 0.12);
  border-color: rgba(245, 199, 109, 0.45);
}

.prow.latest {
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.8);
}

.prow.is-disabled {
  cursor: default;
  opacity: 0.9;
}

.prow-btn {
  display: contents;
}

.prow-no, .rrow-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: min(2.5rem, calc((100% - 2px) * 1.3));
  height: min(1.9rem, calc(100% - 2px));
  border-radius: 999px;
  background: rgba(133, 183, 255, 0.18);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.assigned .prow-no, .assigned .rrow-no {
  background: rgba(245, 199, 109, 0.18);
  color: #ffe6a2;
}

.prow-name, .rrow-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: clamp(0.7rem, calc(var(--row-h) * 0.32), 1rem);
  color: var(--text);
}

.prow-val, .rrow-from {
  font-size: 0.72rem;
  color: var(--muted);
  justify-self: end;
}

.draw-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  min-height: 0;
  flex: 1;
}

.draw-slot {
  width: 100%;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
  padding: 1rem 0.75rem;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.02);
  transition: 0.22s ease;
}

.draw-slot.is-ready {
  border-color: rgba(245, 199, 109, 0.6);
  background: rgba(245, 199, 109, 0.08);
}

.draw-slot.is-blocked {
  border-color: rgba(241, 111, 111, 0.6);
  background: rgba(241, 111, 111, 0.08);
}

.slot-no {
  font-size: clamp(1.3rem, 2.5vw, 2rem);
  font-weight: 800;
}

.slot-name {
  font-size: clamp(0.82rem, 2vw, 1rem);
  opacity: 0.95;
}

.slot-note {
  font-size: 0.72rem;
  color: var(--muted);
}

.launch-btn {
  width: min(100%, 230px);
  padding: 0.85rem 1.3rem;
  font-size: 1rem;
  font-weight: 800;
  background: linear-gradient(135deg, rgba(91,120,255,0.2), rgba(245,199,109,0.2));
}

.launch-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.draw-hint {
  min-height: 1.6rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.draw-key {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.8rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  font-family: inherit;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 16, 0.6);
  z-index: 30;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  width: min(540px, calc(100vw - 2rem));
  max-height: min(80vh, 700px);
  overflow: auto;
  background: #111b30;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.close-btn {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  color: var(--text);
}

.modal-body {
  padding: 1rem;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.setting-block {
  padding: 1rem;
  border-radius: 14px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
}

.setting-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 0.7rem;
  align-items: center;
  margin-bottom: 0.7rem;
}

.setting-row label {
  color: var(--muted);
}

.setting-row input {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.preset-chip {
  padding: 0.4rem 0.8rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.toggle-row input {
  accent-color: var(--primary);
}

.shortcut-line {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

.shortcut-btn {
  flex: 1;
  min-width: 180px;
  padding: 0.7rem 0.8rem;
  font-weight: 700;
}

.mini-btn, .action-btn {
  padding: 0.7rem 0.9rem;
  font-weight: 600;
}

.action-block {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.action-btn.danger {
  background: rgba(241, 111, 111, 0.12);
  border-color: rgba(241,111,111,0.3);
}

.shortcut-note {
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.8rem;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 180px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  padding: 0.8rem 0.9rem;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
}

.history-item strong {
  color: var(--gold);
}

.draw-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 19, 0.7);
  z-index: 40;
}

.draw-overlay.show {
  display: flex;
}

.roulette-wrap {
  width: min(520px, 88vw);
  background: rgba(17,25,46,0.92);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 22px;
  padding: 1rem 1rem 1.2rem;
  box-shadow: var(--shadow);
}

.spin-header {
  text-align: center;
  margin-bottom: 0.7rem;
}

.spin-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.spin-name {
  color: var(--muted);
  margin-top: 0.2rem;
}

.roulette-stage {
  position: relative;
  width: min(76vw, 360px);
  height: min(76vw, 360px);
  margin: 0 auto;
  display: grid;
  place-items: center;
}

.roulette {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    conic-gradient(
      #ff6b6b 0 12.5%,
      #ffd166 12.5% 25%,
      #7bd389 25% 37.5%,
      #4ecdc4 37.5% 50%,
      #5dade2 50% 62.5%,
      #a78bfa 62.5% 75%,
      #f78fb3 75% 87.5%,
      #f5c76d 87.5% 100%
    );
  border: 10px solid rgba(255,255,255,0.2);
  box-shadow: inset 0 0 0 12px rgba(0,0,0,0.16), 0 20px 36px rgba(0,0,0,0.28);
  transform: rotate(0deg);
  transform-origin: center;
  will-change: transform;
  transition: transform 3.6s cubic-bezier(0.08, 0.82, 0.15, 1);
}

.roulette::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.16);
}

.roulette-pointer {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 34px solid #f7f2cf;
  filter: drop-shadow(0 8px 12px rgba(0,0,0,0.34));
  z-index: 2;
}

.roulette-hub {
  position: absolute;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fef3c7, #f5c76d);
  color: #1b1224;
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: 0 0 0 8px rgba(255,255,255,0.12);
}

.spin-result {
  margin-top: 1rem;
  text-align: center;
  min-height: 2rem;
  font-size: clamp(1.2rem, 3vw, 2rem);
  font-weight: 800;
  color: var(--gold);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.4rem;
  padding: 0 0.5rem;
  border-radius: 12px;
  background: rgba(17,25,46,0.6);
  border: 1px solid rgba(255,255,255,0.05);
  color: var(--muted);
  font-size: 0.82rem;
}

.footer-text {
  color: var(--text);
}

@media (max-width: 860px) {
  .board {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "list result"
      "draw draw";
  }

  .pane-list { grid-area: list; }
  .pane-draw { grid-area: draw; }
  .pane-result { grid-area: result; }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 0.55rem 0.6rem 0.6rem;
  }

  .app-bar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .board {
    grid-template-columns: 1fr;
    grid-template-areas:
      "list"
      "draw"
      "result";
  }

  .stat-group {
    order: 3;
    width: 100%;
  }

  .action-group {
    width: 100%;
    justify-content: flex-end;
  }
}
