:root {
  --primary: #3B82F6;
  --primary-dim: rgba(59,130,246,0.15);
  --primary-glow: rgba(59,130,246,0.3);
  --accent: #10B981;
  --accent-dim: rgba(16,185,129,0.15);
  --bg: #0F172A;
  --bg-card: rgba(15,23,42,0.85);
  --bg-card2: rgba(20,30,55,0.7);
  --bg-input: rgba(10,18,35,0.8);
  --border: rgba(59,130,246,0.12);
  --border-hover: rgba(59,130,246,0.25);
  --text: #E2E8F0;
  --text-dim: #94A3B8;
  --text-muted: #64748B;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: 250ms ease;
  --glass: rgba(15,23,42,0.65);
  --glass-border: rgba(59,130,246,0.08);
  --danger: #EF4444;
  --warning: #F59E0B;
  --success: #10B981;
}
[data-theme="light"] {
  --bg: #F8FAFC; --bg-card: rgba(255,255,255,0.9); --bg-card2: rgba(248,250,252,0.9);
  --bg-input: #fff; --border: rgba(59,130,246,0.15); --border-hover: rgba(59,130,246,0.3);
  --text: #1E293B; --text-dim: #475569; --text-muted: #94A3B8;
  --glass: rgba(255,255,255,0.7); --glass-border: rgba(59,130,246,0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  min-height: 100vh; line-height: 1.6; overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 10% 0%, rgba(59,130,246,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 100%, rgba(16,185,129,0.04) 0%, transparent 50%);
}

.app { max-width: 1600px; margin: 0 auto; padding: 0 20px; display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.header { padding: 14px 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.header-left { display: flex; align-items: center; gap: 10px; }
.logo { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; background: var(--primary-dim); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.header h1 { font-size: 1.2rem; font-weight: 700; background: linear-gradient(135deg, var(--primary), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.score-display { font-weight: 700; color: var(--accent); font-size: 0.9rem; padding: 4px 12px; background: var(--accent-dim); border-radius: 20px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 5px; padding: 8px 14px; border-radius: var(--radius-sm); border: none; font-family: var(--font); font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: all var(--transition); white-space: nowrap; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2563EB; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--primary-dim); }
.btn-icon { background: transparent; color: var(--text-dim); border: 1px solid var(--border); width: 34px; height: 34px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); }
.btn-icon:hover { color: var(--text); background: var(--primary-dim); }
.btn-sm { padding: 5px 10px; font-size: 0.75rem; }

/* Challenge Nav */
.challenge-nav { padding: 12px 0; overflow-x: auto; border-bottom: 1px solid var(--border); }
.challenge-list { display: flex; gap: 8px; min-width: max-content; }
.challenge-tab { padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-dim); font-family: var(--font); font-size: 0.78rem; font-weight: 500; cursor: pointer; transition: all var(--transition); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.challenge-tab:hover { border-color: var(--border-hover); color: var(--text); }
.challenge-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.challenge-tab .tab-check { color: var(--accent); font-size: 0.9rem; }

/* Arena */
.arena { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 14px; flex: 1; padding: 16px 0; }

/* Panels */
.panel { background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--glass-border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.panel-header h2 { font-size: 0.85rem; font-weight: 600; }
.panel-body { flex: 1; overflow: hidden; position: relative; }
.panel-footer { padding: 8px 14px; border-top: 1px solid var(--border); }

.badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; background: var(--primary-dim); color: var(--primary); font-weight: 600; }

/* Target */
.target-body { display: flex; align-items: center; justify-content: center; background: #fff; min-height: 300px; }
.target-body .target-canvas { width: 400px; height: 300px; }
.hint { font-size: 0.75rem; color: var(--text-muted); }

/* Editor */
.editor-wrapper { flex: 1; display: flex; }
.code-editor { width: 100%; height: 100%; min-height: 300px; resize: none; background: var(--bg-input); border: none; color: var(--text); font-family: var(--mono); font-size: 0.85rem; line-height: 1.7; padding: 14px 16px; outline: none; tab-size: 2; }
.code-editor::placeholder { color: var(--text-muted); }
.editor-actions { display: flex; align-items: center; gap: 8px; }
.char-count { font-size: 0.72rem; color: var(--text-muted); font-family: var(--mono); }

/* Output */
.output-body { display: flex; align-items: center; justify-content: center; background: #fff; min-height: 300px; }
#outputFrame { width: 400px; height: 300px; border: none; background: #fff; }

/* Scores */
.score-group { display: flex; gap: 8px; }
.accuracy-score { font-size: 0.78rem; font-weight: 700; color: var(--accent); padding: 2px 8px; background: var(--accent-dim); border-radius: 8px; }
.golf-score { font-size: 0.78rem; font-weight: 700; color: var(--primary); padding: 2px 8px; background: var(--primary-dim); border-radius: 8px; }

.diff-toggle { display: flex; gap: 6px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); width: 90%; max-width: 600px; max-height: 70vh; display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 1rem; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.hidden { display: none !important; }

/* History items */
.history-item { padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; }
.history-item-header { display: flex; justify-content: space-between; margin-bottom: 4px; }
.history-item-name { font-weight: 600; font-size: 0.85rem; }
.history-item-score { font-size: 0.78rem; color: var(--accent); font-weight: 600; }
.history-item-code { font-family: var(--mono); font-size: 0.75rem; color: var(--text-dim); white-space: pre-wrap; max-height: 80px; overflow: hidden; background: var(--bg-input); padding: 6px 8px; border-radius: 4px; margin-top: 4px; }
.history-item-date { font-size: 0.7rem; color: var(--text-muted); }

/* Footer */
.footer { padding: 14px 0; text-align: center; font-size: 0.72rem; color: var(--text-muted); border-top: 1px solid var(--border); margin-top: auto; }
.shortcuts-hint { margin-top: 4px; }
kbd { background: var(--primary-dim); padding: 1px 5px; border-radius: 3px; font-family: var(--mono); font-size: 0.68rem; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.panel { animation: fadeIn 0.3s ease; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* Responsive */
@media (max-width: 1024px) { .arena { grid-template-columns: 1fr; } .target-body, .output-body, #outputFrame, .target-body .target-canvas { width: 100%; max-width: 400px; } }
@media (max-width: 768px) {
  .app { padding: 0 12px; }
  .header-right { gap: 4px; }
  .header-right .btn-ghost span { display: none; }
}
@media (max-width: 480px) {
  .header h1 { font-size: 1rem; }
  .code-editor { font-size: 0.78rem; min-height: 200px; }
}
