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

html { overflow-x: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem;
  overflow-x: hidden;
}

header { text-align: center; padding: 1.5rem 0 0.5rem; }
header h1 { color: #c9a227; font-size: 1.6rem; }
.subtitle { color: #888; font-size: 0.9rem; }

/* Login overlay */
.login-overlay {
  position: fixed; inset: 0; background: #1a1a2e;
  display: flex; align-items: center; justify-content: center; z-index: 200;
  overflow: hidden;
}
.login-box {
  text-align: center; width: 90%; max-width: 340px;
}
.login-box h1 { color: #c9a227; font-size: 1.6rem; margin-bottom: 0.25rem; }
.login-box .subtitle { margin-bottom: 1.5rem; }
.login-box form {
  display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.75rem;
}
.login-box input {
  padding: 0.6rem 0.75rem; background: #16213e; border: 1px solid #333;
  border-radius: 4px; color: #e0e0e0; font-size: 0.95rem; width: 100%; min-width: 0;
}
.login-box form button {
  padding: 0.6rem 1rem; background: #c9a227; color: #1a1a2e;
  border: none; border-radius: 4px; cursor: pointer; font-weight: 600; font-size: 0.95rem;
}
.login-box form button:hover { background: #ddb832; }
.login-tabs {
  display: flex; margin-bottom: 1rem; border-bottom: 2px solid #333;
}
.login-tab {
  flex: 1; background: none; border: none; color: #888; padding: 0.5rem;
  cursor: pointer; font-size: 0.95rem; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: color 0.2s;
}
.login-tab:hover { color: #ccc; }
.login-tab.active { color: #c9a227; border-bottom-color: #c9a227; }
.form-error { color: #e74c3c; font-size: 0.85rem; text-align: left; }

/* Header user button */
header { position: relative; }
.user-panel-btn {
  position: absolute; top: 1rem; right: 0;
  background: #16213e; border: 1px solid #444; border-radius: 50%;
  width: 2rem; height: 2rem; cursor: pointer; color: #c9a227;
  font-size: 0.85rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.user-panel-btn:hover { background: #1e2f50; }

/* User panel — desktop: dropdown popup anchored near the avatar button */
.user-panel {
  position: fixed; top: 4rem; right: max(1rem, calc(50% - 340px));
  background: #16213e; border: 1px solid #444; border-radius: 8px;
  padding: 1rem 1.25rem; z-index: 150; min-width: 180px;
  display: flex; flex-direction: column; gap: 0.6rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.user-panel-name {
  color: #c9a227; font-weight: 600; font-size: 0.95rem;
  padding-bottom: 0.5rem; border-bottom: 1px solid #333;
}
.user-panel-backdrop { display: none; }

/* User / Campaign bar */
#user-bar {
  display: flex; align-items: center;
  gap: 0.5rem; padding: 0.5rem 0.75rem; background: #0f1a30;
  border-radius: 6px; margin-bottom: 0.5rem; flex-wrap: wrap;
}
.campaign-controls {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; flex: 1;
}
.campaign-select-row {
  display: flex; align-items: center; gap: 0.4rem; flex: 1; min-width: 0;
}
.campaign-actions { display: flex; gap: 0.4rem; align-items: center; }
.campaign-controls label { color: #888; font-size: 0.8rem; white-space: nowrap; }
#campaign-select {
  padding: 0.3rem 0.5rem; background: #16213e; border: 1px solid #333;
  border-radius: 4px; color: #e0e0e0; font-size: 0.8rem; flex: 1; min-width: 0;
}
.btn-small {
  padding: 0.2rem 0.5rem; background: #333; color: #ccc; border: none;
  border-radius: 3px; cursor: pointer; font-size: 0.75rem; white-space: nowrap;
}
.btn-small:hover { background: #444; }
.btn-danger-small { color: #e74c3c; }
.btn-danger-small:hover { background: rgba(231,76,60,0.15); }

/* Tabs */
nav { display: flex; gap: 0.25rem; margin: 1rem 0; border-bottom: 2px solid #333; overflow-x: auto; overflow-y: hidden; }
.tab {
  background: none; border: none; color: #888; padding: 0.6rem 1rem;
  cursor: pointer; font-size: 0.9rem; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: color 0.2s;
}
.tab:hover { color: #ccc; }
.tab.active { color: #c9a227; border-bottom-color: #c9a227; }

.tab-content { display: none; padding: 1rem 0; }
.tab-content.active { display: block; }

h2 { color: #c9a227; margin-bottom: 1rem; font-size: 1.2rem; }
h3 { color: #aaa; font-size: 0.9rem; margin-bottom: 0.5rem; }

/* Forms */
.inline-form {
  display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.inline-form input, .inline-form select {
  flex: 1; min-width: 0; padding: 0.5rem 0.75rem;
  background: #16213e; border: 1px solid #333; border-radius: 4px;
  color: #e0e0e0; font-size: 0.9rem;
}
.inline-form button, .mission-form button[type="submit"], button.big-btn {
  padding: 0.5rem 1rem; background: #c9a227; color: #1a1a2e;
  border: none; border-radius: 4px; cursor: pointer; font-weight: 600;
  font-size: 0.9rem;
}
.inline-form button:hover, .mission-form button[type="submit"]:hover, button.big-btn:hover { background: #ddb832; }

button.big-btn { width: 100%; padding: 0.75rem; font-size: 1rem; margin: 1rem 0; }

/* Mission form */
.mission-form {
  display: flex; flex-direction: column; gap: 0.5rem;
  margin-bottom: 1rem; padding: 0.75rem; background: #0f1a30; border-radius: 6px;
}
.form-row {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.form-row input, .form-row select {
  padding: 0.5rem 0.75rem; background: #16213e; border: 1px solid #333;
  border-radius: 4px; color: #e0e0e0; font-size: 0.9rem;
}
.form-row input { flex: 1; min-width: 0; }
.form-row select { flex: 1; min-width: 0; }
.num-input { max-width: 55px !important; min-width: 55px !important; flex: 0 !important; text-align: center; }
.form-label { color: #888; font-size: 0.85rem; white-space: nowrap; min-width: 60px; }

/* Enemy type input */
.enemy-input-wrap { flex: 1; position: relative; min-width: 0; }
.enemy-input-wrap input { width: 100%; }
.suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 10;
  background: #16213e; border: 1px solid #444; border-radius: 0 0 4px 4px;
  max-height: 150px; overflow-y: auto;
}
.suggestions .suggestion {
  padding: 0.4rem 0.75rem; cursor: pointer; font-size: 0.85rem;
}
.suggestions .suggestion:hover, .suggestions .suggestion.active { background: #1e2f50; }
.suggestions .suggestion.add-new { color: #c9a227; font-style: italic; }

/* Tag pills */
.tag-list { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem; }
.tag-pill {
  font-size: 0.7rem; background: #333; color: #ccc; padding: 0.15rem 0.5rem;
  border-radius: 3px; display: flex; align-items: center; gap: 0.25rem;
}
.tag-pill .remove-tag { cursor: pointer; color: #e74c3c; font-weight: bold; }
.tag-pill.preset-map { background: #2c3e50; color: #3498db; }
.tag-pill.no-gates { background: #2c2c1a; color: #e67e22; }
.tag-pill.starts-other-world { background: #1a2c1a; color: #2ecc71; }
.tag-pill.epic-threat { background: #2c1a1a; color: #e74c3c; }
.tag-pill.enemy { background: #1a1a2c; color: #9b59b6; }

/* Mission number display */
.mission-num {
  font-size: 0.75rem; color: #888; background: #222; padding: 0.1rem 0.4rem;
  border-radius: 3px; font-weight: 600; white-space: nowrap;
}

/* Lists */
.item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 0.75rem; background: #16213e; border-radius: 4px;
  margin-bottom: 0.4rem; flex-wrap: wrap;
}
.item .title { flex: 1; min-width: 0; word-break: break-word; }
.item .source-tag {
  font-size: 0.75rem; background: #333; color: #aaa;
  padding: 0.15rem 0.5rem; border-radius: 3px; white-space: nowrap;
}
.item button {
  background: none; border: none; cursor: pointer; font-size: 0.85rem;
  padding: 0.25rem 0.5rem; border-radius: 3px;
}
.item .btn-delete { color: #e74c3c; }
.item .btn-delete:hover { background: rgba(231,76,60,0.15); }
.item .btn-success { color: #2ecc71; }
.item .btn-success:hover { background: rgba(46,204,113,0.15); }
.item .btn-fail { color: #e67e22; }
.item .btn-fail:hover { background: rgba(230,126,34,0.15); }
.item .btn-undo { color: #3498db; }
.item .btn-undo:hover { background: rgba(52,152,219,0.15); }

.item.completed { opacity: 0.6; }
.result-badge {
  font-size: 0.7rem; font-weight: 700; padding: 0.15rem 0.4rem;
  border-radius: 3px; text-transform: uppercase;
}
.result-badge.success { background: #2ecc71; color: #1a1a2e; }
.result-badge.failure { background: #e67e22; color: #1a1a2e; }

/* Randomizer */
.filter-group { margin-bottom: 0.75rem; }
.filter-hint { font-size: 0.75rem; color: #666; font-weight: normal; }

/* Three-state tag filter */
.tag-filter-group { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag-filter {
  padding: 0.35rem 0.65rem; border-radius: 4px; font-size: 0.85rem;
  cursor: pointer; user-select: none; border: 1px solid #333;
  background: #16213e; color: #888; transition: all 0.15s;
}
.tag-filter[data-state="include"] {
  background: rgba(46,204,113,0.15); color: #2ecc71; border-color: #2ecc71;
}
.tag-filter[data-state="exclude"] {
  background: rgba(231,76,60,0.15); color: #e74c3c; border-color: #e74c3c;
  text-decoration: line-through;
}
.checkbox-group { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.checkbox-group label {
  display: flex; align-items: center; gap: 0.3rem;
  background: #16213e; padding: 0.35rem 0.65rem; border-radius: 4px;
  font-size: 0.85rem; cursor: pointer;
}
.checkbox-group input[type="checkbox"] { accent-color: #c9a227; }

.select-toggle { color: #3498db; cursor: pointer; font-size: 0.8rem; font-weight: normal; }
.select-toggle:hover { text-decoration: underline; }

.sourcebook-filter-list { display: flex; flex-direction: column; gap: 0.3rem; }
.sourcebook-filter-list label {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.85rem; cursor: pointer; padding: 0.2rem 0;
}
.sourcebook-filter-list input[type="checkbox"] { accent-color: #c9a227; }

.result-card {
  background: #16213e; border: 2px solid #c9a227; border-radius: 6px;
  padding: 1.25rem; text-align: center; margin-bottom: 1.5rem;
}
.result-card .mission-name { font-size: 1.3rem; color: #fff; margin-bottom: 0.3rem; }
.result-card .mission-source { color: #888; font-size: 0.9rem; }
.result-actions {
  display: flex; justify-content: center; gap: 0.75rem; margin-top: 1rem;
}
.result-actions button {
  padding: 0.45rem 1.25rem; border-radius: 4px; cursor: pointer;
  font-weight: 600; font-size: 0.9rem;
}
.result-actions .btn-success {
  background: rgba(46,204,113,0.15); color: #2ecc71;
  border: 1px solid #2ecc71;
}
.result-actions .btn-success:hover { background: rgba(46,204,113,0.3); }
.result-actions .btn-fail {
  background: rgba(230,126,34,0.15); color: #e67e22;
  border: 1px solid #e67e22;
}
.result-actions .btn-fail:hover { background: rgba(230,126,34,0.3); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: #1a1a2e; border: 1px solid #333; border-radius: 8px;
  padding: 1.25rem; width: 90%; max-width: 600px; max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 0.75rem; }
.btn-cancel {
  padding: 0.5rem 1rem; background: #444; color: #ccc;
  border: none; border-radius: 4px; cursor: pointer; font-size: 0.9rem;
}
.btn-cancel:hover { background: #555; }

.hidden { display: none !important; }

.empty-state { color: #666; font-style: italic; padding: 1rem 0; }

/* Edit button in mission items */
.item .btn-edit { color: #3498db; }
.item .btn-edit:hover { background: rgba(52,152,219,0.15); }

/* Import / Export */
.import-export-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.import-label { cursor: pointer; }

/* Missions header edit toggle */
.missions-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.missions-header h2 { margin-bottom: 0; }
.missions-header-actions { display: flex; gap: 0.4rem; align-items: center; }
#edit-mode-btn.active { background: #c9a227; color: #1a1a2e; }

/* Collapsible sourcebook groups */
.sourcebook-group { margin-bottom: 0.25rem; }
.sourcebook-header {
  cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0; padding: 0.3rem 0;
}
.sourcebook-header:hover { color: #ddb832; }
.sourcebook-caret {
  font-size: 0.55rem; color: #888;
  display: inline-block; transition: transform 0.15s;
}
.sourcebook-header.expanded .sourcebook-caret { transform: rotate(90deg); }
.sourcebook-count { color: #888; font-size: 0.8rem; font-weight: normal; }
.sourcebook-missions { margin-bottom: 0.75rem; }

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 480px) {
  body { padding: 0.75rem; }

  header h1 { font-size: 1.3rem; }

  /* User panel becomes a slide-in drawer from the right */
  .user-panel-backdrop {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 140;
  }
  .user-panel-backdrop.hidden { display: none !important; }

  .user-panel {
    position: fixed; top: 0; right: -260px; bottom: 0;
    width: 240px; border-radius: 0; border: none; border-left: 1px solid #444;
    padding: 1.5rem 1.25rem; z-index: 150;
    transition: right 0.25s ease;
  }
  .user-panel.open { right: 0; }

  .campaign-controls { flex-direction: column; align-items: stretch; }
  .campaign-select-row { width: 100%; }
  .campaign-actions { width: 100%; }

  .tab { padding: 0.6rem 0.6rem; font-size: 0.85rem; }

  .filter-hint { display: block; margin-top: 0.2rem; }

  .modal { padding: 1rem; }
}
