/* Theme variables live in shared/variables.css — loaded before this file. */

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg, #0f1117);
  color: var(--text, #e2e8f0);
  min-height: 100%;
}

/* ── Theme Toggle ─────────────────────────────── */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  background: var(--surface-2, #22253a);
  border: 1px solid var(--border, #2d3148);
  border-radius: 50%;
  width: 2.2rem;
  height: 2.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text, #e2e8f0);
  transition: background 0.15s;
}
.theme-toggle:hover { background: var(--highlight); }

/* ── Header ───────────────────────────────────── */
.page-header {
  text-align: center;
  padding: 2rem 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.page-header h1 .accent { color: var(--accent-5); }
.page-header h1 .accent-2 { color: var(--accent-3); }

.page-header p {
  color: var(--muted, #8892a4);
  font-size: 0.875rem;
  max-width: 700px;
  margin: 0 auto;
  line-height: 1.5;
}

.page-header .back-link {
  display: inline-block;
  margin-bottom: 0.75rem;
  color: var(--muted, #8892a4);
  text-decoration: none;
  font-size: 0.8rem;
}

.page-header .back-link:hover { color: var(--accent-2); }

/* ── Disclaimer ──────────────────────────────── */
.disclaimer {
  max-width: 800px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  background: rgba(123,94,167,0.1);
  border: 1px solid var(--accent-3);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
  text-align: center;
  line-height: 1.4;
}

.disclaimer strong {
  color: var(--accent-3);
}

/* ── Mobile tab bar ──────────────────────────── */
.mobile-tab-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface, #1a1d27);
  border-bottom: 1px solid var(--border, #2d3148);
}

.mobile-tab {
  flex: 1;
  padding: 0.75rem 0.5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted, #8892a4);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  text-align: center;
}

.mobile-tab:hover { color: var(--text, #e2e8f0); }

.mobile-tab.active {
  color: var(--accent-5);
  border-bottom-color: var(--accent-5);
}

/* ── Main Layout ──────────────────────────────── */
.main-layout {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  max-width: 1600px;
  margin: 0 auto;
  min-height: calc(100vh - 160px);
}

/* ── Left Panel: Level Selector ──────────────── */
.left-panel {
  border-right: 1px solid var(--border, #2d3148);
  overflow-y: auto;
  background: var(--surface, #1a1d27);
}

.panel-header {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #8892a4);
  padding: 0.75rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border, #2d3148);
  position: sticky;
  top: 0;
  background: var(--surface, #1a1d27);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.level-card {
  padding: 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
  cursor: pointer;
  transition: background 0.1s;
}

.level-card:hover { background: var(--highlight); }
.level-card.active { background: var(--highlight); border-left: 3px solid var(--accent-5); }
.level-card.completed { border-left: 3px solid var(--success); }
.level-card.active.completed { border-left: 3px solid var(--accent-5); }

.level-card-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.level-card-desc {
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
  line-height: 1.4;
}

.level-card-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.7rem;
}

.level-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--surface-2, #22253a);
  border: 1px solid var(--border, #2d3148);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted, #8892a4);
  flex-shrink: 0;
}

.level-card.completed .level-number {
  background: rgba(91,163,0,0.15);
  border-color: var(--success);
  color: var(--success);
}

.difficulty-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.difficulty-easy { color: var(--token-agents); background: rgba(91,163,0,0.15); }
.difficulty-medium { color: var(--token-skills); background: rgba(201,122,46,0.15); }
.difficulty-hard { color: var(--token-tools); background: rgba(199,62,62,0.15); }

.defense-badge {
  color: var(--muted, #8892a4);
  font-weight: 500;
  font-size: 0.65rem;
}

.stars-badge {
  color: var(--gold);
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

/* ── Center Panel: Attack Editor ─────────────── */
.center-panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg, #0f1117);
}

.editor-section {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.editor-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.editor-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted, #8892a4);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.token-count-badge {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--accent-2);
  background: rgba(0,158,176,0.1);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: none;
  letter-spacing: 0;
}

/* ── System Prompt Display (read-only) ────────── */
.system-prompt-display {
  width: 100%;
  padding: 0.75rem;
  background: var(--code-bg, #151820);
  color: var(--code-text, #c9d1d9);
  border: 1px solid var(--border, #2d3148);
  border-radius: 6px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  position: relative;
}

.system-prompt-display .redacted {
  color: var(--accent-5);
  font-weight: 600;
}

.defense-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  color: var(--muted, #8892a4);
  margin-top: 0.4rem;
}

.defense-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.65rem;
  background: rgba(199,62,62,0.12);
  color: var(--accent-5);
}

/* ── Chat History ────────────────────────────── */
.chat-history {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 400px;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.chat-message {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message.user {
  background: rgba(0,158,176,0.12);
  border: 1px solid rgba(0,158,176,0.25);
  color: var(--text, #e2e8f0);
  align-self: flex-end;
  margin-left: auto;
}

.chat-message.assistant {
  background: var(--surface, #1a1d27);
  border: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0);
  align-self: flex-start;
}

.chat-message.assistant.leaked {
  border-color: var(--success);
  background: rgba(91,163,0,0.08);
}

.chat-message-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
  display: block;
}

.chat-message.user .chat-message-label { color: var(--accent-2); }
.chat-message.assistant .chat-message-label { color: var(--accent-3); }

.chat-empty {
  text-align: center;
  color: var(--muted, #8892a4);
  font-size: 0.8rem;
  padding: 2rem 1rem;
  font-style: italic;
}

/* ── Attack Input ────────────────────────────── */
.attack-input-wrap {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.attack-textarea {
  flex: 1;
  min-height: 70px;
  padding: 0.75rem;
  background: var(--code-bg, #151820);
  color: var(--code-text, #c9d1d9);
  border: 1px solid var(--border, #2d3148);
  border-radius: 6px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  resize: vertical;
}

.attack-textarea:focus {
  outline: none;
  border-color: var(--accent-5);
}

.send-btn {
  padding: 0.6rem 1.2rem;
  background: var(--accent-5);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
  align-self: flex-end;
}

.send-btn:hover { opacity: 0.9; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.clear-btn {
  padding: 0.4rem 0.8rem;
  background: var(--surface-2, #22253a);
  color: var(--muted, #8892a4);
  border: 1px solid var(--border, #2d3148);
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.1s;
}

.clear-btn:hover { border-color: var(--accent-5); color: var(--accent-5); }

.attempt-counter {
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
  font-variant-numeric: tabular-nums;
}

.attempt-counter strong {
  color: var(--accent-5);
}

/* ── Right Panel: Status ─────────────────────── */
.right-panel {
  border-left: 1px solid var(--border, #2d3148);
  overflow-y: auto;
  background: var(--surface, #1a1d27);
}

/* ── LLM Mode controls ──────────────────────── */
.llm-controls {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.control-group {
  margin-bottom: 0.5rem;
}

.control-group:last-child { margin-bottom: 0; }

.control-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted, #8892a4);
  margin-bottom: 0.25rem;
}

.control-select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: var(--surface-2, #22253a);
  color: var(--text, #e2e8f0);
  border: 1px solid var(--border, #2d3148);
  border-radius: 4px;
  font-size: 0.75rem;
}

.api-config, .webllm-config {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.api-input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: var(--surface-2, #22253a);
  color: var(--text, #e2e8f0);
  border: 1px solid var(--border, #2d3148);
  border-radius: 4px;
  font-size: 0.75rem;
  margin-bottom: 0.4rem;
}

.api-input:focus { outline: none; border-color: var(--accent-2); }

.api-hint {
  font-size: 0.65rem;
  color: var(--muted, #8892a4);
  line-height: 1.4;
}

.load-btn {
  width: 100%;
  padding: 0.5rem;
  background: var(--accent-2);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  margin-bottom: 0.4rem;
}
.load-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.webllm-progress { margin-top: 0.4rem; }

.webllm-progress-bar-wrap {
  position: relative;
  height: 8px;
  background: var(--surface-2, #22253a);
  border-radius: 4px;
  overflow: hidden;
}

.webllm-progress-bar {
  height: 100%;
  background: var(--accent-2);
  transition: width 0.3s;
  width: 0;
}

.webllm-progress-text {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.65rem;
  color: var(--muted, #8892a4);
  text-align: center;
}

/* ── Sampler panel ───────────────────────────── */
.sampler-panel {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

/* ── Result Display ──────────────────────────── */
.result-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.result-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted, #8892a4);
  margin-bottom: 0.75rem;
}

.result-display {
  text-align: center;
  padding: 1rem 0;
}

.result-status {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.result-status.leaked { color: var(--success); }
.result-status.safe { color: var(--accent-5); }
.result-status.pending { color: var(--muted, #8892a4); }

.result-detail {
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
  margin-top: 0.25rem;
}

.result-stars {
  font-size: 1.5rem;
  margin: 0.5rem 0;
  letter-spacing: 0.15em;
}

.star-filled { color: var(--gold); }
.star-empty { color: var(--border, #2d3148); }

.result-score {
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.result-score strong {
  color: var(--accent, #5ba300);
  font-size: 1.1rem;
}

/* ── Level Progress ──────────────────────────── */
.progress-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.progress-bar-wrap {
  height: 12px;
  background: var(--surface-2, #22253a);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-5), var(--accent-3));
  transition: width 0.5s;
  width: 0;
}

.progress-text {
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
  margin-top: 0.4rem;
  text-align: center;
}

/* ── Hints ────────────────────────────────────── */
.hints-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.hints-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted, #8892a4);
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.hints-title:hover { color: var(--accent-4); }

.hints-list {
  list-style: none;
  font-size: 0.75rem;
  color: var(--muted, #8892a4);
}

.hints-list li {
  padding: 0.3rem 0;
  padding-left: 1rem;
  position: relative;
}

.hints-list li::before {
  content: "\1F4A1";
  position: absolute;
  left: 0;
  font-size: 0.7rem;
}

.hint-hidden { display: none; }

/* ── Leaderboard ─────────────────────────────── */
.leaderboard-section {
  padding: 1rem;
}

.leaderboard-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted, #8892a4);
  margin-bottom: 0.5rem;
}

.leaderboard-table {
  width: 100%;
  font-size: 0.72rem;
  border-collapse: collapse;
}

.leaderboard-table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted, #8892a4);
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border, #2d3148);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.leaderboard-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border, #2d3148);
  color: var(--text, #e2e8f0);
}

.leaderboard-table tr:first-child td { color: var(--gold); font-weight: 600; }

.leaderboard-empty {
  text-align: center;
  color: var(--muted, #8892a4);
  font-size: 0.75rem;
  padding: 1rem 0;
  font-style: italic;
}

/* ── Status Bar ──────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1rem;
  font-size: 0.7rem;
  color: var(--muted, #8892a4);
  background: var(--surface, #1a1d27);
  border-top: 1px solid var(--border, #2d3148);
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 0.4rem;
}
.status-dot.ready { background: var(--accent, #5ba300); }
.status-dot.running { background: var(--accent-4); animation: pulse 1s infinite; }
.status-dot.error { background: var(--accent-5); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Celebrations ────────────────────────────── */
.result-section.celebrate {
  animation: resultGlow 1.6s ease-out;
}

@keyframes resultGlow {
  0% { box-shadow: 0 0 0 0 rgba(91,163,0,0.5); }
  40% { box-shadow: 0 0 24px 6px rgba(91,163,0,0.35); }
  100% { box-shadow: 0 0 0 0 rgba(91,163,0,0); }
}

.result-status.pop-in {
  animation: statusPopIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes statusPopIn {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .result-section.celebrate { animation: none; }
  .result-status.pop-in { animation: none; }
}

/* ── Responsive: Tablet ──────────────────────── */
@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .left-panel {
    border-right: none;
    border-bottom: 1px solid var(--border, #2d3148);
    max-height: 300px;
  }

  .right-panel {
    border-left: none;
    border-top: 1px solid var(--border, #2d3148);
  }
}

/* ── Responsive: Mobile ──────────────────────── */
@media (max-width: 768px) {
  .mobile-tab-bar { display: flex; }

  .page-header { padding: 1rem 1rem 0.75rem; }
  .page-header h1 { font-size: 1.3rem; }
  .page-header p { font-size: 0.8rem; }

  .theme-toggle {
    top: 0.6rem;
    right: 0.6rem;
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
  }

  .main-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .left-panel {
    border-right: none;
    border-bottom: 1px solid var(--border, #2d3148);
    max-height: none;
  }

  .right-panel {
    border-left: none;
    border-top: 1px solid var(--border, #2d3148);
  }

  .mobile-hidden { display: none !important; }

  .level-card { padding: 1rem; min-height: 3.5rem; }
  .level-card-title { font-size: 0.95rem; }

  .editor-section { padding: 0.75rem 1rem; }

  .attack-textarea { font-size: 0.85rem; min-height: 60px; }

  .send-btn {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    min-height: 2.75rem;
  }

  .attack-input-wrap {
    flex-direction: column;
  }

  .attack-input-wrap .send-btn {
    width: 100%;
  }

  .chat-message { max-width: 95%; font-size: 0.78rem; }

  .panel-header { padding: 0.6rem 1rem 0.5rem; font-size: 0.72rem; }

  .disclaimer { margin: 0 0.5rem; font-size: 0.7rem; }

  .control-select { font-size: 0.8rem; padding: 0.5rem; min-height: 2.5rem; }
  .api-input { font-size: 0.8rem; padding: 0.5rem; min-height: 2.5rem; }
  .load-btn { font-size: 0.8rem; padding: 0.65rem; min-height: 2.5rem; }

  .status-bar { font-size: 0.68rem; padding: 0.35rem 0.75rem; }
}
