* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #E8732C;
  --primary-dark: #D4621E;
  --primary-light: #FFF3EC;
  --accent: #6B2039;
  --danger: #DC3545;
  --success: #28A745;
  --warning: #F5A623;
  --bg: #F5F6FA;
  --surface: #FFFFFF;
  --surface2: #F8F9FC;
  --text: #333333;
  --text-dim: #888888;
  --border: #E0E3EB;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

/* Login Screen */
.login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.login-title {
  font-size: 1.6em;
  color: var(--accent);
  margin-bottom: 8px;
}
.login-subtitle {
  color: var(--text-dim);
  margin-bottom: 20px;
}
.btn-login {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  font-size: 1em;
}
.login-screen .status-msg { margin-top: 12px; }
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-logout {
  font-size: 0.85em;
  padding: 6px 14px;
}

/* Header */
.header {
  text-align: center;
  padding: 30px 0 20px;
}
.header h1 {
  font-size: 2em;
  color: var(--accent);
}
.subtitle {
  color: var(--text-dim);
  margin-top: 8px;
}

/* Steps Nav */
.steps {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.step {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  border-radius: 8px;
  font-size: 0.85em;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.3s;
}
.step.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.step.done {
  color: var(--success);
}
.step-num {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 0.8em;
  margin-right: 4px;
}
.step.active .step-num {
  background: rgba(255,255,255,0.25);
}

/* Panels */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.panel.hidden { display: none; }
.panel h2 {
  margin-bottom: 16px;
  font-size: 1.4em;
  color: var(--accent);
}

/* Buttons */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 0.95em;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-next { background: var(--primary); color: #fff; }
.btn-next:hover:not(:disabled) { background: var(--primary-dark); }
.btn-back { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-back:hover { color: var(--text); border-color: var(--text-dim); }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2em;
  padding: 8px;
  color: var(--text-dim);
}
.btn-icon:hover { color: var(--text); }

.nav-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
}

/* Step 1 */
.api-tab-content.hidden { display: none; }
.badge-type {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7em;
  font-weight: 600;
  vertical-align: middle;
  margin-right: 4px;
}
.badge-line { background: rgba(6,199,85,0.12); color: #06C755; }
.badge-s8 { background: var(--primary-light); color: var(--primary); }
.saved-tokens-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.saved-tokens-section h3, .new-token-section h3 {
  font-size: 1em;
  margin-bottom: 10px;
  color: var(--text);
}
.saved-tokens-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.saved-token-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.saved-token-item:hover { border-color: var(--primary); }
.saved-token-item.active { border-color: var(--primary); background: var(--primary-light); }
.saved-token-item .st-info { display: flex; flex-direction: column; gap: 2px; }
.saved-token-item .st-name { font-weight: 600; font-size: 0.95em; }
.saved-token-item .st-preview { font-size: 0.8em; color: var(--text-dim); font-family: monospace; }
.saved-token-item .st-actions { display: flex; gap: 4px; }
.test-send-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.test-send-section h3 { font-size: 1em; margin-bottom: 10px; }
.test-send-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.test-send-row input:first-child { flex: 2; }
.test-send-row input:nth-child(2) { flex: 2; }
.test-send-row .btn { white-space: nowrap; }
@media (max-width: 600px) {
  .test-send-row { flex-direction: column; }
}
.btn-delete-token {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.85em;
  padding: 4px 8px;
  border-radius: 4px;
  opacity: 0.6;
}
.btn-delete-token:hover { opacity: 1; background: rgba(220,53,69,0.08); }
.token-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.token-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.token-input-group input {
  flex: 1;
}
input, textarea, select {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95em;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; font-family: monospace; }

.status-msg {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9em;
  display: none;
}
.status-msg.success { display: block; background: rgba(40,167,69,0.08); color: var(--success); border: 1px solid rgba(40,167,69,0.25); }
.status-msg.error { display: block; background: rgba(220,53,69,0.06); color: var(--danger); border: 1px solid rgba(220,53,69,0.2); }

.parse-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.tag-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.tag-section h3 { font-size: 1em; margin-bottom: 8px; }
.tag-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tag-input-row input { flex: 1; }
.tag-input-row .btn { white-space: nowrap; }

.custom-message-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.custom-message-section h3 { font-size: 1em; margin-bottom: 8px; }
.custom-message-section textarea { rows: 3; height: 80px; }

.hint {
  font-size: 0.85em;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.hint a { color: var(--primary); }
.hint code {
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  border: 1px solid var(--border);
}

/* Step 2 Tabs */
.input-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  padding: 8px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9em;
  transition: all 0.2s;
}
.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.tab-content.hidden { display: none; }

.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
  transition: all 0.2s;
}
.file-drop.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* Validation Table */
.validation-result { margin-top: 20px; }
.validation-result h3 { margin-bottom: 10px; }
.participant-table-wrap {
  max-height: 300px;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}
#participantTable {
  width: 100%;
  border-collapse: collapse;
}
#participantTable th {
  background: var(--surface2);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.85em;
  color: var(--text-dim);
  position: sticky;
  top: 0;
}
#participantTable td {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 0.9em;
}
#participantTable tr.invalid { background: rgba(220,53,69,0.04); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 600;
}
.badge-ok { background: rgba(40,167,69,0.1); color: var(--success); }
.badge-err { background: rgba(220,53,69,0.1); color: var(--danger); }

#validSummary {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9em;
}

/* Step 3 Mode Cards */
.mode-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.mode-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-card:hover { border-color: var(--primary); }
.mode-card.selected { border-color: var(--primary); background: var(--primary-light); }
.mode-icon { font-size: 2em; margin-bottom: 8px; }
.mode-card h3 { font-size: 1em; margin-bottom: 4px; }
.mode-card p { font-size: 0.8em; color: var(--text-dim); }

.mode-config {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}
.mode-config.hidden { display: none; }
.mode-config label {
  display: block;
  font-size: 0.85em;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 12px;
}
.mode-config label:first-child { margin-top: 0; }
.mode-config input[type="number"] { width: 120px; }
.mode-config input[type="text"] { width: 100%; }

/* Tier rows */
.tier-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.tier-name { flex: 2; }
.tier-count { flex: 1; max-width: 100px; }
.btn-remove-tier {
  color: var(--danger);
  font-size: 1em;
  width: 32px;
  height: 32px;
}

/* Lottery Area */
.lottery-area {
  text-align: center;
  margin: 20px 0;
}
.btn-lottery {
  padding: 16px 48px;
  font-size: 1.2em;
  background: linear-gradient(135deg, var(--primary), #D4621E);
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(232,115,44,0.25);
}
.btn-lottery:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(232,115,44,0.35); }
.btn-lottery:disabled { opacity: 0.5; transform: none; cursor: not-allowed; }

.lottery-display {
  margin: 20px 0;
  min-height: 120px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.lottery-display.hidden { display: none; }

.slot-machine {
  font-size: 1.4em;
  font-weight: 700;
  padding: 20px 40px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 2px solid var(--primary);
  min-width: 300px;
  color: var(--primary);
  text-align: center;
  box-shadow: 0 2px 12px rgba(232,115,44,0.12);
}

/* Results */
.lottery-results { margin-top: 20px; }
.lottery-results.hidden { display: none; }
.lottery-results h3 { margin-bottom: 12px; }

.result-group {
  margin-bottom: 16px;
}
.result-group-title {
  font-weight: 700;
  font-size: 1em;
  margin-bottom: 8px;
  padding: 6px 12px;
  background: var(--primary-light);
  border-radius: 6px;
  border-left: 3px solid var(--primary);
  color: var(--primary-dark);
}
.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: var(--surface2);
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 0.95em;
}
.result-item .winner-name { font-weight: 600; }
.result-item .winner-id { color: var(--text-dim); font-size: 0.85em; font-family: monospace; }

/* Step 4 Notify */
.notify-preview {
  margin-bottom: 20px;
}
.notify-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface2);
  border-radius: 8px;
  margin-bottom: 6px;
}
.notify-card .nc-left { display: flex; align-items: center; gap: 10px; }
.notify-card .nc-prize {
  font-size: 0.8em;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--primary-light);
  color: var(--primary);
}
.btn-notify {
  width: 100%;
  padding: 16px;
  font-size: 1.1em;
  background: linear-gradient(135deg, var(--success), #1E8E3E);
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.3s;
}
.btn-notify:hover { opacity: 0.9; }
.btn-notify:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-retry {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  font-size: 1em;
  background: var(--warning);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}
.btn-retry:hover { opacity: 0.9; }
.btn-retry:disabled { opacity: 0.5; cursor: not-allowed; }

.notify-progress { margin-top: 20px; text-align: center; }
.notify-progress.hidden { display: none; }
.progress-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #34D399);
  border-radius: 4px;
  transition: width 0.3s;
  width: 0%;
}

.notify-results { margin-top: 20px; }
.notify-results.hidden { display: none; }
.notify-results h3 { margin-bottom: 10px; }
.nr-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface2);
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 0.9em;
}
.nr-success { color: var(--success); }
.nr-fail { color: var(--danger); }

/* Animation */
@keyframes slotSpin {
  0% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; }
}
.spinning { animation: slotSpin 0.1s infinite; }

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}
.pop-in { animation: popIn 0.4s ease-out; }

/* Responsive */
@media (max-width: 600px) {
  .mode-cards { grid-template-columns: 1fr; }
  .steps { flex-wrap: wrap; }
  .step { font-size: 0.75em; }
  .panel { padding: 18px; }
}
