:root {
  --ink: #0d0d0d;
  --paper: #f5f0e8;
  --cream: #ede8da;
  --accent: #c8402a;
  --gold: #d4a84b;
  --muted: #7a7060;
  --border: #cfc8b5;
  --code-bg: #1a1a1a;
  --code-text: #e8d5a0;
  --green: #2a7a4b;
  --success-bg: rgba(42, 122, 75, 0.08);
  --error-bg: rgba(200, 64, 42, 0.08);
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
}

/* NOISE OVERLAY */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 1000;
  opacity: 0.4;
}

/* NAV */
.case-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 40px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 100;
}

.logo {
  font-family: 'Playfair Display', serif;
  font-weight: 900;
  font-size: 1.3rem;
  letter-spacing: -0.5px;
  text-decoration: none;
  color: var(--ink);
}
.logo span { color: var(--accent); }

.case-nav-meta {
  display: flex;
  align-items: center;
  gap: 20px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--muted);
}

.case-badge-nav {
  background: rgba(42, 122, 75, 0.1);
  color: var(--green);
  padding: 4px 10px;
  font-size: 0.65rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* MAIN LAYOUT */
.case-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: calc(100vh - 53px);
}

/* LEFT PANEL — CASE BRIEF + CLUES */
.case-panel {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  max-height: calc(100vh - 53px);
}

.case-header {
  padding: 32px 28px;
  border-bottom: 1px solid var(--border);
}

.case-industry {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.case-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  font-weight: 900;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.case-brief {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--muted);
}

.case-brief strong {
  color: var(--ink);
  font-weight: 500;
}

/* SCHEMA EXPLORER */
.schema-section {
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}

.schema-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
}

.schema-toggle:hover { color: var(--ink); }

.schema-content {
  display: none;
  margin-top: 16px;
}

.schema-content.open {
  display: block;
}

.schema-table {
  margin-bottom: 14px;
}

.schema-table-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.schema-table-name:hover { color: var(--accent); }

.schema-cols {
  display: none;
  padding-left: 16px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.8;
}

.schema-cols.open { display: block; }

.schema-col-pk { color: var(--gold); }
.schema-col-type { color: #888; margin-left: 4px; }

/* CLUE TIMELINE */
.clue-timeline {
  padding: 24px 28px;
}

.clue-timeline-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 20px;
}

.clue-item {
  position: relative;
  padding: 16px 20px;
  padding-left: 36px;
  margin-bottom: 2px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s;
}

.clue-item:hover { background: var(--cream); }
.clue-item.active { background: var(--cream); }

/* Timeline line */
.clue-item::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.clue-item:first-child::before { top: 50%; }
.clue-item:last-child::before { bottom: 50%; }

/* Timeline dot */
.clue-item::after {
  content: '';
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--paper);
  z-index: 1;
}

.clue-item.completed::after {
  background: var(--green);
  border-color: var(--green);
}

.clue-item.active::after {
  border-color: var(--accent);
  background: var(--paper);
  box-shadow: 0 0 0 3px rgba(200, 64, 42, 0.15);
}

.clue-item.locked::after {
  background: var(--cream);
  border-color: var(--border);
}

.clue-num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}

.clue-item.locked .clue-num { color: var(--border); }

.clue-name {
  font-family: 'Playfair Display', serif;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
}

.clue-item.locked .clue-name { color: var(--border); }
.clue-item.completed .clue-name { color: var(--green); }

/* RIGHT PANEL — SQL WORKSPACE */
.sql-workspace {
  display: flex;
  flex-direction: column;
  background: var(--code-bg);
  max-height: calc(100vh - 53px);
}

/* Query prompt area */
.query-prompt {
  padding: 24px 32px;
  background: #111;
  border-bottom: 1px solid #2a2a2a;
}

.prompt-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}

.prompt-text {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #ccc;
}

.prompt-hint {
  margin-top: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: #555;
  cursor: pointer;
  transition: color 0.2s;
}

.prompt-hint:hover { color: #888; }
.prompt-hint.revealed { color: #888; }

/* Editor */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #0d0d0d;
  border-bottom: 1px solid #1e1e1e;
}

.editor-toolbar-left {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: #555;
  letter-spacing: 1px;
}

.btn-run {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 20px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
}
.btn-run:hover { background: #a83220; }

.btn-check {
  background: var(--green);
  color: white;
  border: none;
  padding: 8px 20px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
  margin-left: 8px;
}
.btn-check:hover { background: #1d5c38; }

.editor-area {
  flex: 1;
  min-height: 160px;
}

.editor-area textarea {
  width: 100%;
  height: 100%;
  min-height: 160px;
  background: #0d0d0d;
  color: var(--code-text);
  border: none;
  padding: 16px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  line-height: 1.7;
  resize: none;
  outline: none;
  tab-size: 2;
}

.editor-area textarea::placeholder {
  color: #444;
}

/* Results */
.results-panel {
  border-top: 1px solid #2a2a2a;
  background: #111;
  overflow: auto;
  max-height: 50%;
  min-height: 100px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid #1e1e1e;
  position: sticky;
  top: 0;
  background: #111;
}

.results-header-text {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: #555;
  letter-spacing: 1px;
}

.results-table-wrap {
  overflow-x: auto;
  padding: 0 16px 16px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
}

.results-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--gold);
  border-bottom: 1px solid #2a2a2a;
  white-space: nowrap;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.results-table td {
  padding: 6px 12px;
  color: #bbb;
  border-bottom: 1px solid #1a1a1a;
  white-space: nowrap;
}

.results-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Error & Messages */
.result-error {
  padding: 16px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: var(--accent);
  line-height: 1.5;
}

.result-empty {
  padding: 16px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  color: #555;
}

/* Validation feedback */
.validation-result {
  padding: 16px;
  margin: 0 16px 16px;
  border-radius: 3px;
  font-size: 0.85rem;
  line-height: 1.6;
}

.validation-result.success {
  background: rgba(42, 122, 75, 0.1);
  border: 1px solid rgba(42, 122, 75, 0.3);
  color: #6fcf97;
}

.validation-result.fail {
  background: rgba(200, 64, 42, 0.1);
  border: 1px solid rgba(200, 64, 42, 0.3);
  color: #e88;
}

/* Clue unlock animation */
.clue-unlock-banner {
  display: none;
  padding: 20px 32px;
  background: rgba(42, 122, 75, 0.08);
  border-top: 2px solid var(--green);
  animation: slideDown 0.4s ease;
}

.clue-unlock-banner.visible {
  display: block;
}

.unlock-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 8px;
}

.unlock-message {
  font-size: 0.88rem;
  line-height: 1.7;
  color: #ccc;
  margin-bottom: 12px;
}

.btn-next-clue {
  background: var(--green);
  color: white;
  border: none;
  padding: 10px 24px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.2s;
}
.btn-next-clue:hover { background: #1d5c38; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* CASE SOLVED */
.case-solved-banner {
  display: none;
  padding: 32px;
  background: #0d0d0d;
  border-top: 3px solid var(--gold);
  text-align: center;
}

.case-solved-banner.visible {
  display: block;
}

.solved-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.solved-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--gold);
  margin-bottom: 8px;
}

.solved-text {
  font-size: 0.9rem;
  color: #aaa;
  line-height: 1.7;
  max-width: 600px;
  margin: 0 auto 20px;
}

.solved-recommendation {
  background: #111;
  border: 1px solid #2a2a2a;
  padding: 20px 24px;
  text-align: left;
  margin-top: 20px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.solved-rec-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}

.solved-rec-text {
  font-size: 0.85rem;
  color: #aaa;
  line-height: 1.7;
}

/* Responsive */
@media (max-width: 900px) {
  .case-layout {
    grid-template-columns: 1fr;
  }
  .case-panel {
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sql-workspace {
    max-height: none;
    min-height: 70vh;
  }
}
