/* Spells — browse the full spellbook */

#panel-spells.panel[hidden] { display: none !important; }

#panel-spells.panel.active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 8rem);
  max-height: calc(100dvh - 8rem);
  overflow: hidden;
  padding: 0;
  margin: 0;
}

body.sp-tab-active #panel-spells.panel.active {
  min-height: calc(100dvh - 5.5rem);
  max-height: calc(100dvh - 5.5rem);
}

body.sp-tab-active .site-footer,
body.sp-tab-active .site-header .subtitle { display: none; }

body.sp-tab-active .sp-browse-view .sp-body {
  flex: 1 1 auto;
  min-height: 0;
}

.sp-shell {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  background: var(--bg);
}

.sp-top {
  flex: 0 0 auto;
  padding: 0.55rem 0.75rem 0.45rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.sp-top h2 {
  margin: 0 0 0.2rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 400;
}

.sp-top-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
}

.sp-hint {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.sp-hint[hidden] { display: none !important; }

.sp-mode-nav {
  display: flex;
  gap: 0.25rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.sp-mode-btn {
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.sp-mode-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sp-cast-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sp-cast-view[hidden],
.sp-browse-view[hidden] { display: none !important; }

.sp-browse-view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sp-cast-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 0.55rem 0.65rem 0;
}

.sp-cast-main {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
}

.sp-cast-stage {
  flex: 1 1 auto;
  min-height: 10rem;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #080a10;
  border: 2px dashed var(--border);
  border-radius: calc(var(--radius) + 2px);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sp-cast-stage.sp-drop-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 60px rgba(201, 162, 39, 0.14);
}

.sp-cast-stage.sp-generating .sp-cast-preview {
  opacity: 0.45;
  filter: blur(1px);
}

.sp-cast-empty {
  margin: 0;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.sp-cast-empty[hidden] { display: none !important; }

.sp-cast-preview {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.sp-cast-preview[hidden] { display: none !important; }

.sp-cast-meta {
  flex: 0 0 auto;
}

.sp-cast-subject-wrap {
  margin-bottom: 0.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid rgba(201, 162, 39, 0.28);
  border-radius: var(--radius);
  background: rgba(201, 162, 39, 0.06);
}

.sp-cast-subject-wrap[hidden] { display: none !important; }

.sp-cast-subject-label {
  display: block;
  margin: 0 0 0.2rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.sp-cast-subject-hint {
  margin: 0 0 0.4rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.sp-cast-subject {
  display: block;
  width: 100%;
  min-height: 4.5rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
  resize: vertical;
}

.sp-cast-subject:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.22);
}

.sp-cast-import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.sp-cast-import-actions[hidden] { display: none !important; }

.sp-cast-analysis {
  margin-top: 0.45rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.sp-cast-analysis[hidden] { display: none !important; }

.sp-cast-analysis-title {
  margin: 0 0 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

.sp-cast-analysis-desc {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text);
}

.sp-cast-analysis-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.35rem;
}

.sp-cast-analysis-note {
  margin: 0;
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.sp-cast-applied {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  min-height: 1.5rem;
  margin-bottom: 0.45rem;
}

.sp-cast-applied-empty {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.sp-cast-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: rgba(201, 162, 39, 0.18);
  font-size: 0.68rem;
  color: #e8d8a0;
}

.sp-cast-chip-rm {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
}

.sp-cast-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.sp-cast-prompt {
  flex: 1 1 160px;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.sp-cast-status {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sp-cast-status.ok { color: #8ec9a0; }
.sp-cast-status.error { color: #e8a090; }
.sp-cast-status.pending { color: var(--accent); }

.sp-cast-tray { flex: 0 0 auto; }

#panel-spells .sp-spell { cursor: grab; touch-action: none; }

.sp-pinned-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sp-browse-view .sp-toolbar {
  flex: 0 0 auto;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sp-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.sp-search {
  flex: 1 1 180px;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.sp-select {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}

.sp-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sp-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr min(18rem, 34vw);
  gap: 0;
}

.sp-grid-wrap {
  min-height: 0;
  overflow-y: auto;
  padding: 0.65rem;
}

.sp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.55rem;
}

.sp-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font: inherit;
  color: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.sp-card:hover,
.sp-card.sp-card-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.25);
}

.sp-card.sp-card-pinned::before {
  content: "★";
  position: absolute;
  top: 0.25rem;
  right: 0.3rem;
  color: var(--accent);
  font-size: 0.7rem;
  z-index: 1;
}

.sp-card {
  position: relative;
}

.sp-card-thumb {
  aspect-ratio: 1;
  background: #000;
}

.sp-card-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sp-card-meta {
  padding: 0.35rem 0.4rem 0.45rem;
}

.sp-card-num {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.03em;
}

.sp-card-title {
  margin: 0.1rem 0 0;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sp-load-more-wrap {
  text-align: center;
  padding: 0.75rem 0 0.25rem;
}

.sp-detail {
  border-left: 1px solid var(--border);
  background: rgba(8, 10, 18, 0.94);
  overflow-y: auto;
  padding: 0.65rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.sp-detail-empty {
  margin: auto 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.sp-detail-preview {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.sp-detail-preview img {
  display: block;
  width: 100%;
  height: auto;
}

.sp-detail-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.25;
}

.sp-detail-sub {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sp-detail-desc {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text);
}

.sp-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.sp-tag {
  padding: 0.2rem 0.45rem;
  font-size: 0.62rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(201, 162, 39, 0.25);
}

.sp-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.sp-btn {
  padding: 0.4rem 0.65rem;
  font: inherit;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

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

.sp-btn.accent {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sp-spell-text {
  margin: 0;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, monospace;
  font-size: 0.62rem;
  line-height: 1.45;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 8rem;
  overflow-y: auto;
}

@media (max-width: 860px) {
  .sp-body { grid-template-columns: 1fr; }
  .sp-detail {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 40vh;
  }
}