:root {
  --bg-deep: #060d1c;
  --bg-mid: #0f2f5c;
  --bg-light: #1c5a9e;
  --panel: #0c1830;
  --panel-2: #101f3d;
  --line: #23345c;
  --ink: #eef2fb;
  --ink-dim: #91a0c4;
  --gold: #d9b04a;
  --gold-bright: #f0cd7a;
  --text-pink: #f6c3e0;
  --text-cyan: #8fe9f2;
  --good: #47c98a;
  --danger: #ff8a7a;
  --font-display: 'Noto Sans JP', 'Rajdhani', sans-serif;
  --font-body: 'Noto Sans JP', sans-serif;
  --font-num: 'Rajdhani', 'Noto Sans JP', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  .reel-track { transition-duration: 0.01ms !important; }
  * { animation-duration: 0.01ms !important; }
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(16px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.brand .rings {
  display: inline-flex;
  gap: 4px;
}
.brand .rings span {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block;
  border: 2px solid var(--gold);
}
.brand .rings span:nth-child(2) { border-color: var(--text-cyan); }
.brand .rings span:nth-child(3) { border-color: var(--text-pink); }
.brand h1 {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(16px, 2.2vw, 21px);
  letter-spacing: 0.02em;
  margin: 0;
  text-wrap: balance;
}
.brand .sub {
  font-family: var(--font-num);
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 0.08em;
  margin-top: 2px;
}
.status-chip {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  padding: 7px 16px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-chip.is-offline {
  background: linear-gradient(135deg, #ff8a7a, #c0392b);
}

.stage {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  padding: clamp(14px, 2.5vw, 28px);
  align-items: start;
}
@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.panel h2 {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--gold-bright);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel h2::before {
  content: '';
  width: 6px; height: 6px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--gold);
}
.panel p.hint {
  font-size: 12.5px;
  color: var(--ink-dim);
  line-height: 1.7;
  margin: 0 0 10px;
}

textarea#bulkInput {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  padding: 10px 11px;
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.6;
}
textarea#bulkInput:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

input.code-input, input.text-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  padding: 10px 11px;
  font-family: var(--font-num);
  font-size: 14px;
}
input.code-input:focus, input.text-input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

.btn {
  font-family: var(--font-num);
  font-weight: 700;
  letter-spacing: 0.03em;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
.btn-gold { background: linear-gradient(135deg, var(--gold-bright), var(--gold)); color: #23180a; }
.btn-ghost { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid #6e2c22; }
.btn-danger:hover { background: rgba(255,138,122,0.1); }
.btn-danger.is-confirming { background: var(--danger); color: #2a0e0a; border-color: var(--danger); font-weight: 700; }
.btn-danger.is-confirming:hover { background: var(--danger); filter: brightness(1.08); }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 22px; font-size: 17px; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; filter: none; transform: none; }

.row-gap { display: flex; gap: 8px; margin-top: 10px; }
.row-gap .btn { flex: 1; }

.match-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 30vh;
  overflow-y: auto;
}
.match-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px;
}
.match-item.is-used { opacity: 0.45; border-style: dashed; }
.match-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex-shrink: 0; }
.match-item.is-used .dot { background: var(--ink-dim); }
.match-item .label {
  flex: 1;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.match-item .mini {
  background: transparent; border: none; color: var(--ink-dim);
  cursor: pointer; font-size: 12px; padding: 3px 5px; border-radius: 5px; line-height: 1;
}
.match-item .mini:hover { color: var(--ink); background: rgba(255,255,255,0.06); }
.empty-hint { color: var(--ink-dim); font-size: 12.5px; padding: 8px 2px; line-height: 1.6; }

.count-row {
  display: flex; justify-content: space-between;
  font-family: var(--font-num); font-size: 12.5px; color: var(--ink-dim);
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}
.count-row b { color: var(--gold-bright); font-weight: 700; }

.screen-panel {
  padding: 0;
  overflow: hidden;
  position: relative;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 30px 70px -30px rgba(0,0,0,0.7);
}
.screen {
  position: relative;
  background:
    radial-gradient(ellipse 120% 90% at 50% 50%, var(--bg-light) 0%, var(--bg-mid) 48%, var(--bg-deep) 100%);
  min-height: clamp(420px, 62vh, 620px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
  pointer-events: none;
}
.screen-caption {
  position: absolute;
  top: 20px;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: clamp(11px, 1.4vw, 13px);
  letter-spacing: 0.18em;
  color: rgba(238,242,251,0.55);
  text-transform: uppercase;
  z-index: 2;
}

.reel-window {
  position: relative;
  width: min(88%, 720px);
  height: clamp(280px, 40vh, 400px);
  overflow: hidden;
  z-index: 1;
}
.reel-window::before,
.reel-window::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 38%;
  z-index: 3;
  pointer-events: none;
}
.reel-window::before {
  top: 0;
  background: linear-gradient(180deg, var(--bg-mid) 0%, rgba(15,47,92,0.5) 55%, transparent 100%);
}
.reel-window::after {
  bottom: 0;
  background: linear-gradient(0deg, var(--bg-mid) 0%, rgba(15,47,92,0.5) 55%, transparent 100%);
}

.reel-center-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: clamp(70px, 11vh, 96px);
  z-index: 2;
  pointer-events: none;
  border-top: 1px solid rgba(240,205,122,0.0);
  border-bottom: 1px solid rgba(240,205,122,0.0);
}
.reel-center-frame.is-armed {
  border-top: 1px solid rgba(240,205,122,0.35);
  border-bottom: 1px solid rgba(240,205,122,0.35);
}

.reel-track {
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  will-change: transform;
}
.reel-entry {
  height: clamp(70px, 11vh, 96px);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0 24px;
}
.reel-entry span {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(22px, 3.6vw, 38px);
  line-height: 1.2;
  text-align: center;
  text-wrap: balance;
  background: linear-gradient(180deg, var(--text-pink) 0%, #ffffff 45%, var(--text-cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 10px rgba(0,0,0,0.35));
}
.reel-entry.is-winner span {
  background: linear-gradient(180deg, var(--gold-bright) 0%, #fff8e4 50%, var(--gold-bright) 100%);
  -webkit-background-clip: text;
  background-clip: text;
}
.reel-entry.is-placeholder span {
  background: none;
  -webkit-text-fill-color: rgba(238,242,251,0.28);
  color: rgba(238,242,251,0.28);
}
.reel-entry.is-spacer span {
  visibility: hidden;
}

.picker-row {
  z-index: 2;
  display: flex;
  gap: 22px;
  margin-top: 26px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.picker-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.picker-label {
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(238,242,251,0.45);
}
.pattern-picker {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: rgba(6,13,28,0.4);
  border: 1px solid rgba(238,242,251,0.14);
  border-radius: 999px;
}
.pattern-btn {
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: rgba(238,242,251,0.65);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.pattern-btn:hover { color: var(--ink); }
.pattern-btn:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
.pattern-btn.is-active {
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: #23180a;
}
.pattern-btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.draw-actions {
  z-index: 2;
  display: flex;
  gap: 12px;
  margin: 16px 0 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.draw-actions .btn-lg { min-width: 220px; }

.result-banner {
  z-index: 2;
  margin-bottom: 22px;
  font-family: var(--font-num);
  font-size: 14px;
  color: rgba(238,242,251,0.7);
  min-height: 20px;
  text-align: center;
}
.result-banner b { color: var(--gold-bright); font-weight: 700; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

footer.note {
  text-align: center;
  color: var(--ink-dim);
  font-size: 12px;
  padding: 6px 20px 26px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3,7,16,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(480px, 100%);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 70px -20px rgba(0,0,0,0.6);
}
.modal-box h3 {
  margin: 0;
  padding: 18px 20px 4px;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--gold-bright);
}
.modal-box p.modal-hint {
  margin: 0;
  padding: 0 20px 12px;
  font-size: 12.5px;
  color: var(--ink-dim);
  line-height: 1.6;
}
.modal-preview-list {
  list-style: none;
  margin: 0;
  padding: 0 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-preview-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-num);
  font-size: 13.5px;
}
.modal-preview-list li:last-child { border-bottom: none; }
.modal-preview-list .modal-preview-index {
  color: var(--ink-dim);
  font-size: 11.5px;
  min-width: 22px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  padding: 14px 20px 20px;
}
.modal-actions .btn { flex: 1; }

.code-panel {
  max-width: 640px;
  margin: 24px auto 0;
}
.code-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.code-row input.code-input { flex: 1; }
.share-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.share-url-row input.text-input { flex: 1; font-size: 12.5px; }
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
  background: var(--good);
  margin-right: 6px;
  box-shadow: 0 0 6px var(--good);
}
.conn-dot.is-offline { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
