/* ===================================================================
 * BeatForge - core CSS
 * Pure CSS + SVG based, zero external assets
 * 4 themes: lofi, cyber, 8bit, cosmic
 * =================================================================== */

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

html, body {
  height: 100%;
  width: 100%;
  font-family: 'Trebuchet MS', 'Verdana', sans-serif;
  overflow-x: hidden;
  color: var(--fg, #1a1a1a);
  background: var(--bg, #ffeed0);
  transition: background 0.5s ease, color 0.5s ease;
}

a { color: var(--accent, #e76f51); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ====== Theme variables ====== */
body.theme-lofi {
  --bg: #f6e3c5;
  --bg-2: #efd2a4;
  --fg: #2a1f17;
  --accent: #e76f51;
  --accent-2: #f4a261;
  --panel: rgba(255, 240, 215, 0.85);
  --panel-border: rgba(231, 111, 81, 0.35);
  --sound-bg: #fff5dd;
  --char-bg: #f7d9a8;
  --char-active: #ffb84d;
  --char-glow: rgba(255, 184, 77, 0.55);
}
body.theme-cyber {
  --bg: #0a0420;
  --bg-2: #1b0540;
  --fg: #e8e8ff;
  --accent: #00f5ff;
  --accent-2: #ff00ff;
  --panel: rgba(20, 8, 50, 0.7);
  --panel-border: rgba(0, 245, 255, 0.5);
  --sound-bg: #160842;
  --char-bg: #1f0a55;
  --char-active: #ff00ff;
  --char-glow: rgba(0, 245, 255, 0.7);
}
body.theme-8bit {
  --bg: #1c1c2c;
  --bg-2: #2a2a44;
  --fg: #f8f8f8;
  --accent: #7cfc00;
  --accent-2: #ff6b35;
  --panel: rgba(40, 40, 60, 0.85);
  --panel-border: rgba(124, 252, 0, 0.4);
  --sound-bg: #2a2a44;
  --char-bg: #33334d;
  --char-active: #ff6b35;
  --char-glow: rgba(124, 252, 0, 0.5);
}
body.theme-cosmic {
  --bg: #050018;
  --bg-2: #0d0030;
  --fg: #d8d8ff;
  --accent: #7b68ee;
  --accent-2: #00bfff;
  --panel: rgba(15, 5, 50, 0.7);
  --panel-border: rgba(123, 104, 238, 0.5);
  --sound-bg: #150040;
  --char-bg: #1c0a55;
  --char-active: #00bfff;
  --char-glow: rgba(123, 104, 238, 0.6);
}

/* ====== Layout ====== */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
}

.nav .logo {
  font-weight: bold;
  font-size: 22px;
  letter-spacing: 1px;
  color: var(--fg);
}
.nav .logo .accent { color: var(--accent); }

.nav .nav-links a {
  margin-left: 16px;
  color: var(--fg);
  font-weight: 600;
  opacity: 0.85;
}
.nav .nav-links a:hover { color: var(--accent); text-decoration: none; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 12px 80px 12px;
  position: relative;
}

.theme-switcher {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  padding: 6px 10px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
}
.theme-switcher .ts-label { font-size: 12px; opacity: 0.7; margin-right: 4px; }
.theme-switcher .ts-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.theme-switcher .ts-btn:hover { background: rgba(255,255,255,0.08); }
.theme-switcher .ts-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--char-glow);
}

/* ====== Stage / Characters ====== */
.stage {
  width: 100%;
  max-width: 1100px;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 8px;
  padding: 30px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  margin-bottom: 24px;
  position: relative;
}

.character {
  flex: 1 1 0;
  max-width: 130px;
  aspect-ratio: 1 / 1.3;
  background: var(--char-bg);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 4px 10px 4px;
  position: relative;
  border: 2px solid transparent;
  transition: all 0.25s ease;
  cursor: pointer;
  user-select: none;
}
.character.drag-over {
  border-color: var(--accent);
  transform: scale(1.05);
}
.character.active {
  background: var(--char-active);
  border-color: var(--accent-2);
  box-shadow: 0 0 24px var(--char-glow), 0 0 40px var(--char-glow);
  animation: char-bob 0.8s ease-in-out infinite alternate;
}
@keyframes char-bob {
  from { transform: translateY(0); }
  to   { transform: translateY(-6px); }
}

.character .char-svg {
  width: 80%;
  height: 70%;
  display: block;
}
.character .char-svg svg { width: 100%; height: 100%; }
.character .char-label {
  font-size: 11px;
  margin-top: 4px;
  font-weight: 700;
  text-align: center;
  line-height: 1;
  min-height: 12px;
  color: var(--fg);
}
.character.active .char-label { color: #fff; text-shadow: 0 0 4px #000; }
.character .char-slot {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 9px;
  opacity: 0.5;
  font-weight: 700;
}

/* ====== Sound dock ====== */
.dock {
  width: 100%;
  max-width: 1100px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  margin-bottom: 24px;
}
.sound-icon {
  aspect-ratio: 1 / 1;
  background: var(--sound-bg);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--panel-border);
  cursor: grab;
  user-select: none;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  padding: 4px;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
}
.sound-icon:hover { transform: translateY(-3px); box-shadow: 0 4px 10px rgba(0,0,0,0.15); }
.sound-icon:active, .sound-icon.dragging { cursor: grabbing; opacity: 0.5; }
.sound-icon .si-svg {
  width: 50%;
  height: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sound-icon .si-svg svg { width: 100%; height: 100%; }
.sound-icon .si-label {
  font-size: 10px;
  margin-top: 2px;
  line-height: 1;
  color: var(--fg);
  opacity: 0.85;
}
.sound-icon .si-type {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 8px;
  opacity: 0.4;
  text-transform: uppercase;
}

/* ====== Action bar ====== */
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 24px;
}
.btn {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
.btn:active { transform: translateY(0); }
.btn.btn-ghost {
  background: transparent;
  color: var(--fg);
  border: 2px solid var(--accent);
}
.btn.btn-danger { background: #c0392b; }

/* ====== Modal ====== */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-back.show { display: flex; }
.modal {
  background: var(--panel);
  color: var(--fg);
  padding: 24px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  width: 90%;
  max-width: 400px;
  backdrop-filter: blur(10px);
}
.modal h3 { margin-bottom: 14px; }
.modal label { display: block; margin: 10px 0 4px 0; font-size: 13px; }
.modal input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.05);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
}
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ====== Plaza / works page ====== */
.plaza-header {
  text-align: center;
  margin-bottom: 20px;
  padding: 20px 10px;
}
.plaza-header h1 {
  font-size: 36px;
  margin-bottom: 8px;
}
.plaza-header p { opacity: 0.7; }

.plaza-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 24px;
}
.plaza-filter .filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  transition: all 0.2s;
}
.plaza-filter .filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.works-grid {
  width: 100%;
  max-width: 1200px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.work-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.work-card.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--char-glow);
  animation: pulse 1.5s ease-in-out 3;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
.work-card:hover { transform: translateY(-3px); box-shadow: 0 6px 18px rgba(0,0,0,0.15); }

.work-card .wc-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
}
.work-card .wc-author {
  font-size: 12px;
  opacity: 0.7;
}
.work-card .wc-theme {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  width: fit-content;
}
.work-card .wc-preview {
  display: flex;
  gap: 4px;
  height: 36px;
  align-items: flex-end;
  background: rgba(0,0,0,0.1);
  border-radius: 6px;
  padding: 4px;
}
.work-card .wc-preview .pv-cell {
  flex: 1;
  background: var(--char-bg);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.work-card .wc-preview .pv-cell.on { background: var(--accent); }
.work-card .wc-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
  align-items: center;
}
.work-card .like-btn {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.work-card .like-btn:hover { border-color: var(--accent); }
.work-card .like-btn.liked { background: #e91e63; color: #fff; border-color: #e91e63; }
.work-card .like-btn .heart { color: #e91e63; }
.work-card .like-btn.liked .heart { color: #fff; }
.work-card .play-btn {
  flex: 1;
  background: var(--accent);
  color: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  opacity: 0.6;
}
.empty-state h2 { margin-bottom: 8px; }

/* ====== Recording indicator ====== */
.rec-indicator {
  position: fixed;
  top: 70px;
  right: 20px;
  background: rgba(231, 111, 81, 0.95);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  display: none;
  z-index: 999;
  animation: blink 1s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.rec-indicator.show { display: block; }

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--accent);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  z-index: 2000;
  transition: transform 0.3s ease;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ====== About page ====== */
.about {
  max-width: 720px;
  margin: 0 auto;
  padding: 30px 20px;
  line-height: 1.7;
}
.about h1 { margin-bottom: 16px; }
.about p { margin-bottom: 14px; opacity: 0.9; }
.about ul { margin-left: 24px; opacity: 0.85; }

/* ====== Footer ====== */
.foot {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  opacity: 0.5;
  border-top: 1px solid var(--panel-border);
}

/* ====== Responsive ====== */
@media (max-width: 768px) {
  .stage { padding: 16px 6px; gap: 4px; }
  .character { max-width: none; }
  .character .char-label { font-size: 9px; }
  .dock { grid-template-columns: repeat(4, 1fr); padding: 10px; }
  .nav { padding: 8px 12px; }
  .nav .logo { font-size: 18px; }
  .nav .nav-links a { margin-left: 10px; font-size: 14px; }
  .plaza-header h1 { font-size: 26px; }
  .works-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
}
@media (max-width: 480px) {
  .character .char-slot { display: none; }
  .theme-switcher { padding: 4px 6px; }
  .theme-switcher .ts-btn { padding: 4px 8px; font-size: 11px; }
  .theme-switcher .ts-label { display: none; }
}
