/* ─── Reset & Base ─────────────────────────────────────────────────────── */

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

:root {
  --bg-deep: #0e0e1a;
  --bg-surface: #1c1c38;
  --bg-card: #2a2a50;
  --bg-card-hover: #363660;
  --border: #606090;
  --border-light: #7a7ab8;
  --text: #e8e8f8;
  --text-dim: #b8b8d8;
  --text-bright: #ffffff;
  --accent: #b388ff;
  --accent2: #80cbc4;
  --gold: #ffd54f;
  --danger: #ff6b9d;
  --success: #69f0ae;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
}

/* ─── Ambient Background ──────────────────────────────────────────────── */

.bg-ambient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(98, 0, 234, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(0, 188, 212, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(179, 136, 255, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(10, 10, 18, 1) 0%, rgba(10, 10, 18, 1) 100%);
  pointer-events: none;
  z-index: 0;
}

/* ─── Toast ───────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  padding: 12px 24px;
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── App Layout ──────────────────────────────────────────────────────── */

#app {
  position: relative;
  height: 100vh;
  z-index: 1;
}

.app-grid {
  display: grid;
  grid-template-columns: 420px 1fr;
  height: 100vh;
  gap: 0;
}

/* ─── Left Panel ──────────────────────────────────────────────────────── */

.panel-left {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-width: 240px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 1px;
}

.header-stats {
  font-size: 11px;
  color: var(--text-dim);
}

/* ─── Component Tabs ──────────────────────────────────────────────────── */

.component-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover {
  color: var(--text-bright);
  background: rgba(255,255,255,0.05);
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ─── Component List ──────────────────────────────────────────────────── */

.component-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
  background: rgba(0,0,0,0.15);
}
.component-list::-webkit-scrollbar {
  width: 4px;
}
.component-list::-webkit-scrollbar-track {
  background: transparent;
}
.component-list::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 2px;
}

.component-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font: inherit;
  color: inherit;
  width: 100%;
  text-align: left;
  box-shadow: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.component-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.component-card:hover {
  background: rgba(255,255,255,0.12);
  border-color: var(--border-light);
  border-left-width: 4px !important;
  transform: translateX(3px);
}
.component-card.active {
  border-color: var(--accent);
  background: rgba(179, 136, 255, 0.15);
}

.comp-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 22px;
  border: 2px solid;
  flex-shrink: 0;
}

.sign-icon {
  position: relative;
}

.comp-info {
  flex: 1;
  min-width: 0;
}

.comp-name {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.3px;
}

.comp-cat {
  font-size: 10px;
  color: var(--text);
  font-weight: 400;
}

.comp-desc {
  font-size: 11px;
  color: var(--text);
  margin-top: 2px;
  line-height: 1.3;
}

.btn-sm {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.btn-sm:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Category colors for sign cards */
.category-directional { border-left: 3px solid #4fc3f7; }
.category-semiDirectional { border-left: 3px solid #ffd54f; }
.category-nonDirectional { border-left: 3px solid #69f0ae; }
.category-asymmetric { border-left: 3px solid #ff6b9d; }

/* ─── Spell Circle Area ───────────────────────────────────────────────── */

.spell-circle-area {
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-deep);
}

.spell-ring-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-align: center;
}

.spell-circle {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 0 auto;
}

.circle-bg {
  position: absolute;
  inset: -15px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.04) 0%, transparent 70%);
  border: 1px solid rgba(255,255,255,0.04);
}

.circle-ring {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  transition: all 0.5s;
}
.circle-ring.quality-good {
  border-color: var(--accent2);
  box-shadow: 0 0 25px rgba(128, 203, 196, 0.3), inset 0 0 25px rgba(128, 203, 196, 0.1);
}
.circle-ring.quality-poor {
  border-color: #7a4040;
  box-shadow: 0 0 15px rgba(255, 107, 157, 0.2);
}
.circle-ring.has-signs {
  border-color: var(--accent);
  box-shadow: 0 0 30px rgba(179, 136, 255, 0.35), inset 0 0 30px rgba(179, 136, 255, 0.1);
}

/* Sigil slot */
.sigil-slot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.08);
  transition: all 0.3s;
  z-index: 2;
}
.sigil-slot:hover {
  border-color: var(--accent);
  background: rgba(179, 136, 255, 0.12);
}
.slot-placeholder {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
}
.placed-sigil {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid;
  transition: all 0.3s;
}

.glyph-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  filter: invert(1);
  opacity: 0.95;
  pointer-events: none;
}

.glyph-icon-center {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: invert(1);
  opacity: 0.95;
  pointer-events: none;
}

/* ─── Sign Slots ──────────────────────────────────────────────────────── */

.sign-slots {
  position: absolute;
  inset: 0;
}

.sign-slot {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px dashed var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.04);
  transition: all 0.3s;
  font-size: 12px;
}
.sign-slot:nth-child(1) { top: 0; left: 50%; transform: translate(-50%, -50%); }
.sign-slot:nth-child(2) { top: 25%; right: -10px; transform: translate(50%, -50%); }
.sign-slot:nth-child(3) { bottom: 25%; right: -10px; transform: translate(50%, 50%); }
.sign-slot:nth-child(4) { bottom: 0; left: 50%; transform: translate(-50%, 50%); }
.sign-slot:nth-child(5) { bottom: 25%; left: -10px; transform: translate(-50%, 50%); }
.sign-slot:nth-child(6) { top: 25%; left: -10px; transform: translate(-50%, -50%); }
.sign-slot .placed-sign {
  font-size: 11px;
  text-align: center;
  line-height: 1.2;
  color: var(--text-bright);
  text-shadow: 0 0 8px currentColor;
  font-weight: 600;
}

.sign-slot .slot-content {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  background: rgba(255,255,255,0.03);
}
.sign-slot .slot-content:hover {
  border-color: var(--accent);
}

/* ─── Slot Actions ─────────────────────────────────────────────────── */
.sign-slot .slot-actions {
  display: none;
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  gap: 2px;
  z-index: 5;
}
.sign-slot:hover .slot-actions {
  display: flex;
}

.slot-btn {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  font-size: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.invert-btn { background: rgba(255, 107, 157, 0.3); color: var(--danger); }
.invert-btn:hover { background: var(--danger); color: #fff; }
.remove-btn { background: rgba(255, 50, 50, 0.3); color: #ff5050; }
.remove-btn:hover { background: #ff5050; color: #fff; }

.slot-size {
  display: none;
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
}
.sign-slot:hover .slot-size {
  display: block;
}
.slot-size input {
  width: 40px;
  height: 2px;
  appearance: none;
  background: var(--border-light);
  border-radius: 1px;
  outline: none;
}
.slot-size input::-webkit-slider-thumb {
  appearance: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* ─── Ring Quality Control ────────────────────────────────────────────── */

.ring-quality-control, .sigil-size-control {
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.sigil-size-control {
  bottom: -50px;
}
.ring-quality-control label, .sigil-size-control label {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.ring-quality-control input, .sigil-size-control input {
  width: 60px;
  height: 3px;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.ring-quality-control input::-webkit-slider-thumb,
.sigil-size-control input::-webkit-slider-thumb {
  appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* ─── Action Bar ──────────────────────────────────────────────────────── */

.action-bar {
  display: flex;
  gap: 8px;
  margin-top: 60px;
  justify-content: center;
}

.btn {
  padding: 10px 24px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  letter-spacing: 0.5px;
}
.btn-cast {
  background: linear-gradient(135deg, #7c4dff, #b388ff);
  color: #fff;
  box-shadow: 0 4px 15px rgba(124, 77, 255, 0.3);
}
.btn-cast:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(124, 77, 255, 0.4);
}
.btn-cast:active {
  transform: translateY(0);
}
.btn-clear {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-clear:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ─── Right Panel ─────────────────────────────────────────────────────── */

.panel-right {
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  overflow: hidden;
}

.canvas-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#spellCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 18, 0.6);
  backdrop-filter: blur(2px);
  transition: opacity 0.5s;
}

.overlay-content {
  text-align: center;
}

.orb-guide {
  font-size: 22px;
  color: var(--text);
  font-weight: 400;
  letter-spacing: 2px;
  animation: pulse-glow 3s ease-in-out infinite;
}

.orb-sub {
  font-size: 13px;
  color: var(--text);
  margin-top: 8px;
  opacity: 0.7;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ─── Spell Status ────────────────────────────────────────────────────── */

.spell-status {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.status-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-bright);
}
.status-label.failure {
  color: var(--danger);
}
.status-label.success {
  color: var(--success);
}

.status-bars {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

.stat-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--text);
  font-weight: 500;
}

.bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ─── Spell Details ───────────────────────────────────────────────────── */

.spell-details {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  max-height: 200px;
  overflow-y: auto;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px 12px;
  margin-bottom: 8px;
}

.details-grid > div {
  display: flex;
  flex-direction: column;
}

.dt {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dd {
  font-size: 12px;
  color: var(--text-bright);
  font-weight: 500;
}

.applied-signs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0;
}

.applied-sign {
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text);
}
.applied-sign.inverted {
  border-color: var(--danger);
  color: var(--danger);
}

.warnings {
  margin-top: 6px;
}

.warning {
  font-size: 11px;
  color: var(--gold);
  padding: 4px 0;
}

/* ─── History ─────────────────────────────────────────────────────────── */

.history-section {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.history-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: color 0.2s;
}
.history-header:hover {
  color: var(--text);
}

.history-count {
  background: var(--bg-card);
  padding: 0 6px;
  border-radius: 8px;
  font-size: 10px;
  min-width: 18px;
  text-align: center;
}

.toggle-arrow {
  margin-left: auto;
  transition: transform 0.2s;
}

.history-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 20px;
}
.history-list.open {
  max-height: 300px;
  padding: 8px 20px 12px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 2px;
  transition: background 0.2s;
}
.history-item:hover {
  background: var(--bg-card);
}
.history-item.success {
  color: var(--text);
}
.history-item.failure {
  color: var(--danger);
}
.hist-icon {
  font-size: 14px;
}
.hist-name {
  flex: 1;
}
.hist-quality {
  font-size: 10px;
  color: var(--text-dim);
}

/* ─── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 800px) {
  .app-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .panel-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .details-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ─── Element Animations ──────────────────────────────────────────────── */

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: 0 0 5px rgba(179, 136, 255, 0.2); }
  50% { box-shadow: 0 0 20px rgba(179, 136, 255, 0.4); }
}

.sigil-card.active {
  animation: glow-pulse 2s ease-in-out infinite;
}
