*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-alt: #0f3460;
  --text: #eaeaea;
  --text-muted: #a0a0b0;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --gold: #f5c542;
  --border: #2a2a4a;
  --success: #2ecc71;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 28px;
}

.header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-user-label {
  font-size: 0.85rem;
  color: var(--gold);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-modal.hidden {
  display: none;
}

.auth-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.auth-modal-panel {
  position: relative;
  z-index: 1;
  width: min(400px, calc(100vw - 32px));
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.auth-modal-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.auth-modal-desc {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.auth-field input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
}

.auth-error {
  margin: 0;
  font-size: 0.85rem;
  color: #e85d5d;
}

.auth-error.hidden {
  display: none;
}

.auth-form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.config-status {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-bottom: 28px;
}

@media (max-width: 820px) {
  .main {
    grid-template-columns: 1fr;
  }
}

.wheel-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pointer-label-slot {
  box-sizing: border-box;
  height: calc(2 * 1.35 * 1.25rem + 16px);
  max-width: 360px;
  width: 100%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pointer-label {
  box-sizing: border-box;
  margin: 0;
  padding: 8px 20px;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  color: var(--pointer-color, var(--gold));
  background: var(--surface-alt);
  border: 2px solid var(--pointer-color, var(--gold));
  border-radius: 10px;
  box-shadow: var(--shadow);
  transition: color 0.15s ease, border-color 0.15s ease;
  width: 100%;
  max-height: 100%;
  word-break: break-word;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.wheel-container {
  position: relative;
  width: 420px;
  height: 420px;
  max-width: 100%;
}

#wheel-canvas {
  width: 100%;
  height: auto;
  border-radius: 50%;
  box-shadow: var(--shadow), 0 0 0 4px var(--surface-alt);
  transition: transform 0.1s ease;
}

.wheel-container.spinning #wheel-canvas {
  filter: brightness(1.05);
}

.pointer {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 32px solid var(--gold);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
  z-index: 10;
}

.pointer::after {
  content: "";
  position: absolute;
  top: -34px;
  left: -8px;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--gold);
}

.wheel-controls {
  text-align: center;
}

.current-label {
  margin-top: 12px;
  font-size: 1.1rem;
  color: var(--gold);
  font-weight: 600;
}

.info-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mode-tabs {
  display: flex;
  gap: 8px;
}

.tab {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.tab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tab.active {
  background: var(--surface-alt);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.panel.hidden {
  display: none;
}

.flow-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.flow-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.select-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.95rem;
}

.progress-block {
  margin-top: 4px;
}

.progress-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-bar {
  height: 8px;
  background: var(--surface-alt);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 4px;
  transition: width 0.4s ease;
}

.result-block.hidden {
  display: none;
}

.result-block h2,
.history-block h2,
.output-header h2 {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.last-result {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--gold);
  min-height: 1.8em;
}

.history-list {
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.88rem;
}

.history-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.history-list li:last-child {
  border-bottom: none;
}

.history-list .highlight {
  color: var(--gold);
  font-weight: 600;
}

.output-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.output-text {
  width: 100%;
  min-height: 480px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.7;
  resize: vertical;
  font-family: inherit;
}

.output-archive-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.output-archive-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.output-archive-header h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

.output-archive-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.output-archive-empty {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.output-archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.output-archive-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.output-archive-item:last-child {
  border-bottom: none;
}

.output-archive-meta {
  min-width: 0;
  flex: 1;
}

.output-archive-meta time {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.output-archive-preview {
  display: block;
  font-size: 0.88rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.output-archive-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

.file-label {
  display: inline-block;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-alt);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 100;
  transition: opacity 0.3s;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

.file-protocol-warning {
  max-width: 520px;
  margin: 48px auto;
  padding: 24px 28px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  line-height: 1.6;
}

.file-protocol-warning.hidden {
  display: none;
}

.file-protocol-warning code {
  background: rgba(0, 0, 0, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
}

.file-protocol-warning a {
  color: var(--accent, #3b82f6);
  font-weight: 600;
}

/* --- Editor panel --- */
.editor-panel {
  margin-bottom: 28px;
}

#play-info-section.hidden {
  display: none;
}

.main.edit-mode-active {
  grid-template-columns: 1fr;
  margin-bottom: 16px;
}

.main.edit-mode-active .wheel-section {
  margin: 0 auto;
}

.editor-panel.hidden {
  display: none;
}

#play-output-section.hidden {
  display: none;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: 8px 0;
}

.editor-title {
  font-size: 1.25rem;
  color: var(--gold);
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.editor-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.editor-tab {
  padding: 8px 16px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
}

.editor-tab:hover {
  color: var(--text);
  background: var(--surface);
}

.editor-tab.active {
  color: var(--gold);
  background: var(--surface);
  font-weight: 600;
}

.editor-content.hidden {
  display: none;
}

.editor-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 400px;
}

.editor-errors {
  list-style: none;
  margin: 0 0 12px;
  padding: 12px 16px;
  background: rgba(233, 69, 96, 0.15);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #ffb4c0;
  font-size: 0.9rem;
}

.editor-errors.hidden {
  display: none;
}

.editor-errors li + li {
  margin-top: 4px;
}

.editor-errors-title {
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  margin-left: -1em;
  margin-bottom: 6px;
}

.editor-field {
  margin-bottom: 16px;
}

.editor-field label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.editor-field input[type="text"],
.editor-field input[type="number"],
.editor-field select,
.editor-field textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.editor-field textarea {
  min-height: 480px;
  line-height: 1.6;
  resize: vertical;
}

.editor-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.editor-row .editor-field {
  flex: 1;
  min-width: 140px;
}

.editor-split {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
}

@media (max-width: 720px) {
  .editor-split {
    grid-template-columns: 1fr;
  }
}

.editor-wheel-list {
  list-style: none;
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.editor-wheel-list li {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.editor-wheel-list li:last-child {
  border-bottom: none;
}

.editor-wheel-list li:hover {
  background: var(--surface-alt);
}

.editor-wheel-list li.active {
  background: var(--surface-alt);
  border-left: 3px solid var(--gold);
}

.editor-wheel-list .wheel-id {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.editor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.editor-table th,
.editor-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.editor-table input[type="text"],
.editor-table input[type="number"] {
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
}

.editor-table input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 0;
  border: none;
  cursor: pointer;
}

.editor-step-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--surface-alt);
}

.editor-step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.editor-step-summary {
  font-weight: 600;
  color: var(--gold);
}

.editor-step-actions {
  display: flex;
  gap: 4px;
}

.editor-step-actions .btn {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.editor-map-section {
  margin-bottom: 24px;
}

.editor-map-section h3 {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--text);
}

.editor-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.editor-checkbox-row input {
  width: auto;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.editor-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.editor-section-title {
  margin: 16px 0 8px;
  font-size: 1rem;
}

.editor-tutorial {
  max-width: 820px;
  line-height: 1.75;
  font-size: 0.95rem;
  color: var(--text);
}

.editor-tutorial .tutorial-lead {
  color: var(--text-muted);
  margin: 0 0 16px;
}

.editor-tutorial h3 {
  margin: 24px 0 10px;
  font-size: 1.08rem;
  color: var(--gold);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.editor-tutorial h3:first-child {
  margin-top: 0;
}

.editor-tutorial h4 {
  margin: 14px 0 6px;
  font-size: 0.98rem;
  color: var(--text);
}

.editor-tutorial p {
  margin: 0 0 10px;
  color: var(--text-muted);
}

.editor-tutorial ol,
.editor-tutorial ul {
  padding-left: 1.35em;
  margin: 0 0 12px;
}

.editor-tutorial li + li {
  margin-top: 6px;
}

.editor-tutorial-dl {
  margin: 0 0 12px;
}

.editor-tutorial-dl dt {
  font-weight: 600;
  margin-top: 12px;
  color: var(--text);
}

.editor-tutorial-dl dd {
  margin: 4px 0 0 0;
  color: var(--text-muted);
}

.editor-tutorial code {
  font-size: 0.88em;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: #ffd89b;
}

.editor-tutorial-note {
  margin: 12px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--gold);
  background: rgba(245, 197, 66, 0.08);
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.editor-tutorial-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 14px;
  font-size: 0.88rem;
}

.editor-tutorial-table th,
.editor-tutorial-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.editor-tutorial-table th {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  white-space: nowrap;
}

.editor-tutorial-table td {
  color: var(--text-muted);
}
