﻿:root {
  --bg: #050612;
  --bg-elevated: rgba(12, 16, 40, 0.96);
  --bg-elevated-soft: rgba(18, 22, 58, 0.9);
  --accent: #7b5cff;
  --accent-soft: rgba(123, 92, 255, 0.2);
  --accent-strong: #d85cff;
  --accent-alt: #3ad2ff;
  --text: #f7f7ff;
  --text-muted: #9ca2cf;
  --danger: #ff5c7a;
  --success: #3ad68f;
  --border-subtle: rgba(255, 255, 255, 0.04);
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.55);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-pill: 999px;
  --transition-fast: 160ms ease-out;
  --transition-med: 220ms ease-out;
  --anim-panel: 280ms cubic-bezier(0.24, 0.82, 0.32, 1);
  --font-display: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Inter", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Liberation Mono", "Courier New", monospace;
  --outline: 0 0 0 2px rgba(58, 210, 255, 0.6);
  --layout-max-width: 1400px;
  --surface: var(--bg-elevated);
  --input-bg: var(--bg-elevated-soft);
}

/* THEME: DARK (DEFAULT) */
.theme-dark,
body:not([class*="theme-"]) {
  --bg: #050612;
  --bg-elevated: rgba(12, 16, 40, 0.96);
  --bg-elevated-soft: rgba(18, 22, 58, 0.9);
  --accent: #7b5cff;
  --accent-soft: rgba(123, 92, 255, 0.2);
  --accent-strong: #d85cff;
  --accent-alt: #3ad2ff;
  --text: #f7f7ff;
  --text-muted: #9ca2cf;
  --border-subtle: rgba(255, 255, 255, 0.04);
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.55);
  --surface: var(--bg-elevated);
  --input-bg: var(--bg-elevated-soft);
}

/* THEME: LIGHT */
.theme-light {
  --bg: #f5f6fb;
  --bg-elevated: #ffffff;
  --bg-elevated-soft: #f7f7ff;
  --accent: #4b5dff;
  --accent-soft: rgba(75, 93, 255, 0.12);
  --accent-strong: #f15df5;
  --accent-alt: #00c4ff;
  --text: #101224;
  --text-muted: #6c6f91;
  --border-subtle: rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.2);
  --surface: var(--bg-elevated);
  --input-bg: var(--bg-elevated-soft);
}

/* THEME: NEON */
.theme-neon {
  --bg: #0a0a0f;
  --bg-elevated: rgba(20, 10, 30, 0.96);
  --bg-elevated-soft: rgba(30, 15, 45, 0.9);
  --accent: #00ff88;
  --accent-soft: rgba(0, 255, 136, 0.2);
  --accent-strong: #00ffff;
  --accent-alt: #ff00ff;
  --text: #ffffff;
  --text-muted: #88ffaa;
  --border-subtle: rgba(0, 255, 136, 0.15);
  --shadow-soft: 0 18px 45px rgba(0, 255, 136, 0.3);
  --surface: var(--bg-elevated);
  --input-bg: var(--bg-elevated-soft);
}

/* THEME: GRADIENT */
.theme-gradient {
  --bg: #1a0a2e;
  --bg-elevated: rgba(26, 10, 46, 0.96);
  --bg-elevated-soft: rgba(35, 15, 60, 0.9);
  --accent: #ff6b9d;
  --accent-soft: rgba(255, 107, 157, 0.2);
  --accent-strong: #c44569;
  --accent-alt: #f8b500;
  --text: #ffffff;
  --text-muted: #c9a8d9;
  --border-subtle: rgba(255, 107, 157, 0.2);
  --shadow-soft: 0 18px 45px rgba(255, 107, 157, 0.25);
  --surface: var(--bg-elevated);
  --input-bg: var(--bg-elevated-soft);
}

/* THEME: HIGH CONTRAST */
.theme-high-contrast {
  --bg: #000000;
  --bg-elevated: #1a1a1a;
  --bg-elevated-soft: #2a2a2a;
  --accent: #ffff00;
  --accent-soft: rgba(255, 255, 0, 0.3);
  --accent-strong: #ffffff;
  --accent-alt: #00ffff;
  --text: #ffffff;
  --text-muted: #cccccc;
  --border-subtle: rgba(255, 255, 255, 0.3);
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.8);
  --surface: var(--bg-elevated);
  --input-bg: var(--bg-elevated-soft);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font-display);
  font-size: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: relative;
  overflow-x: hidden;
  transition: background var(--transition-med), color var(--transition-med);
}

.bg-gradient-layer {
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(circle at 10% 0%, rgba(124, 58, 237, 0.38), transparent 55%),
    radial-gradient(circle at 90% 0%, rgba(14, 165, 233, 0.35), transparent 55%),
    radial-gradient(circle at 0% 100%, rgba(236, 72, 153, 0.32), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(34, 197, 94, 0.32), transparent 55%);
  opacity: 0.32;
  filter: blur(1px);
  pointer-events: none;
  transform: translate3d(0, 0, 0);
  will-change: transform;
  animation: floatGradient 20s ease-in-out infinite alternate;
  z-index: -2;
}

.theme-light .bg-gradient-layer {
  opacity: 0.16;
}

@keyframes floatGradient {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    transform: translate3d(-30px, 20px, 0) scale(1.04);
  }
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: clamp(12px, 1vw + 0.5rem, 16px) clamp(16px, 1.5vw + 0.5rem, 24px);
  box-shadow: var(--shadow-soft);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(22px) saturate(140%);
}

.header-content {
  max-width: var(--layout-max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(12px, 1vw + 0.5rem, 16px);
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  height: clamp(28px, 2vw + 0.5rem, 32px);
  width: clamp(28px, 2vw + 0.5rem, 32px);
  object-fit: contain;
  border-radius: clamp(6px, 0.5vw + 0.25rem, 8px);
  background: radial-gradient(circle at 30% 0%, var(--accent-soft), rgba(15, 23, 42, 0.4));
  border: 1px solid var(--accent-soft);
  padding: clamp(3px, 0.25vw + 0.125rem, 4px);
}

.header-app-name {
  font-size: clamp(1.125rem, 0.875rem + 1.25vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.theme-select {
  padding: 6px 28px 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  appearance: none;
  cursor: pointer;
  transition: border var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca2cf' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px;
}

.theme-select:hover {
  border-color: var(--accent-soft);
}

.theme-select:focus {
  box-shadow: var(--outline);
  border-color: var(--accent-alt);
}

/* Main Layout */
main {
  max-width: 1600px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr minmax(280px, 300px);
  gap: clamp(16px, 2vw + 1rem, 32px);
  padding: clamp(16px, 2vw + 1rem, 32px);
  flex: 1;
  width: 100%;
}

@media (min-width: 1900px) {
  main {
    max-width: 1800px;
    grid-template-columns: minmax(360px, 450px) 1fr minmax(320px, 350px);
  }
}

/* Tablet Layout (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
  main {
    grid-template-columns: minmax(300px, 380px) 1fr minmax(260px, 280px);
    gap: 24px;
    padding: 24px;
  }

  /* Panel adjustments for tablet */
  #input-panel,
  #result-panel,
  #historyPanel {
    min-width: unset;
    max-width: 100%;
  }

  #result-panel {
    min-width: unset;
  }

  .header-content {
    gap: 12px;
  }
}

/* Mobile Layout (< 768px) */
@media (max-width: 768px) {
  /* Main Layout - Convert to stacked flex layout */
  main {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 16px;
    max-width: 100%;
    grid-template-columns: unset;
  }

  /* Panel Width Constraints Removal */
  #input-panel,
  #result-panel,
  #historyPanel {
    width: 100%;
    min-width: unset;
    max-width: 100%;
    margin: 0;
    border-radius: 18px;
    padding: 20px;
  }

  #historyPanel {
    order: 99; /* move history to bottom */
  }

  /* Result Panel Min-Width Fix */
  #result-panel {
    min-width: unset;
  }

  /* Typography Optimization */
  h1, h2, h3 {
    font-size: 1.1rem;
  }

  #input-panel h2,
  #result-panel h2,
  #historyPanel h3 {
    font-size: 1.1rem;
  }

  label,
  .input-row label,
  .input-group label {
    font-size: 0.9rem;
  }

  textarea,
  select,
  input[type="text"] {
    font-size: 0.95rem;
  }

  /* Touch Target Sizing */
  button,
  select,
  input[type="text"],
  textarea {
    padding: 14px 16px;
    min-height: 48px;
  }

  button.btn-primary {
    font-size: 1rem;
    border-radius: 14px;
  }

  /* Input Section Spacing */
  .input-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .input-row {
    margin-bottom: 16px;
  }

  /* Lyrics Section Mobile Formatting */
  .lyrics-block pre {
    font-size: 0.95rem;
    padding: 14px;
    line-height: 1.55;
    border-radius: 14px;
  }

  .lyrics-block {
    margin-bottom: 20px;
  }

  /* History Panel Mobile Optimization */
  #historyList .history-entry {
    padding: 14px 18px;
    font-size: 0.95rem;
    border-radius: 10px;
  }

  /* Header Mobile Adjustments */
  header {
    padding: 12px 16px;
  }

  .header-content {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .header-title {
    width: 100%;
  }

  .header-controls {
    width: 100%;
  }

  .theme-select {
    width: 100%;
    max-width: 100%;
  }
}

/* Small Mobile Devices (< 480px) */
@media (max-width: 480px) {
  main {
    padding: 12px;
    gap: 16px;
  }

  #input-panel,
  #result-panel,
  #historyPanel {
    padding: 16px;
    border-radius: 12px;
  }

  .header-logo {
    height: 24px;
    width: 24px;
  }

  .header-app-name {
    font-size: 1rem;
  }
}

/* Panels */
#input-panel,
#result-panel,
#historyPanel {
  width: 100%;
  min-width: min(360px, 100%);
  max-width: 100%;
  background: var(--surface);
  border-radius: clamp(12px, 1.5vw, 16px);
  padding: clamp(16px, 1.5vw + 0.5rem, 24px);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(22px) saturate(140%);
  position: relative;
  overflow: hidden;
}

#input-panel::before,
#result-panel::before,
#historyPanel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 0 0, var(--accent-soft), transparent 55%);
  opacity: 0.4;
  pointer-events: none;
  mix-blend-mode: screen;
}

#input-panel > *,
#result-panel > *,
#historyPanel > * {
  position: relative;
  z-index: 1;
}

/* Input Panel */
#input-panel h2 {
  margin: 0 0 clamp(16px, 1.25vw + 0.5rem, 20px) 0;
  font-size: clamp(1.125rem, 0.875rem + 1.25vw, 1.5rem);
  font-weight: 700;
  color: var(--text);
}

.input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.input-row label {
  font-size: clamp(0.75rem, 0.7rem + 0.25vw, 0.85rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}


.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: clamp(0.75rem, 0.7rem + 0.25vw, 0.85rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

textarea,
input[type="text"],
select {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--input-bg);
  padding: clamp(10px, 0.75vw + 0.5rem, 14px) clamp(12px, 0.875vw + 0.5rem, 14px);
  color: var(--text);
  font-family: inherit;
  font-size: clamp(0.875rem, 0.8rem + 0.375vw, 0.9rem);
  resize: vertical;
  outline: none;
  transition: border var(--transition-fast), box-shadow var(--transition-fast),
    background var(--transition-fast);
}

textarea {
  min-height: 100px;
}

textarea:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--accent-alt);
  box-shadow: var(--outline);
  background: var(--input-bg);
}

select {
  appearance: none;
  cursor: pointer;
  position: relative;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca2cf' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 10px;
}

.input-group {
  position: relative;
}

.error-text {
  font-size: 0.8rem;
  color: var(--danger);
  min-height: 1.2em;
}

/* Button */
.btn-primary {
  width: 100%;
  padding: clamp(12px, 0.75vw + 0.5rem, 14px) 0;
  border-radius: clamp(10px, 0.75vw + 0.25rem, 12px);
  font-weight: 600;
  font-size: clamp(0.875rem, 0.8rem + 0.375vw, 0.95rem);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: none;
  cursor: pointer;
  color: #020617;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow:
    0 12px 35px rgba(15, 23, 42, 0.7),
    0 0 0 1px rgba(15, 23, 42, 0.2);
  transition:
    transform var(--transition-med),
    box-shadow var(--transition-med),
    filter 160ms ease-out;
  min-width: min(150px, 100%);
}

.btn-primary:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow:
    0 18px 40px rgba(15, 23, 42, 0.8),
    0 0 0 1px rgba(15, 23, 42, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow:
    0 8px 18px rgba(15, 23, 42, 0.8),
    0 0 0 1px rgba(15, 23, 42, 0.3);
  filter: brightness(0.97);
}

.btn-primary:focus-visible {
  outline: none;
  box-shadow: var(--outline);
}

.btn-primary[disabled] {
  cursor: wait;
  opacity: 0.7;
  filter: grayscale(0.25) brightness(0.9);
  transform: translateY(0);
}

/* Result Panel */
#result-panel {
  flex: 1;
  min-width: 0;
}

#result-panel h2 {
  margin: 0 0 clamp(16px, 1.25vw + 0.5rem, 20px) 0;
  font-size: clamp(1.125rem, 0.875rem + 1.25vw, 1.5rem);
  font-weight: 700;
  color: var(--text);
}

.lyrics-block {
  margin-bottom: 24px;
}

.lyrics-block:last-child {
  margin-bottom: 0;
}

.lyrics-block h3 {
  margin: 0 0 clamp(6px, 0.5vw + 0.25rem, 8px) 0;
  font-size: clamp(0.8rem, 0.75rem + 0.25vw, 0.9rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.lyrics-block pre {
  white-space: pre-wrap;
  background: var(--input-bg);
  padding: clamp(12px, 0.875vw + 0.5rem, 14px);
  border-radius: clamp(10px, 0.75vw + 0.25rem, 12px);
  font-family: var(--font-mono);
  font-size: clamp(0.8rem, 0.75rem + 0.375vw, 0.9rem);
  line-height: 1.6;
  color: var(--text);
  margin: 0;
  border: 1px solid var(--border-subtle);
  overflow-wrap: break-word;
  word-break: break-word;
}

.lyric-text.empty {
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--font-display);
}

/* History Panel */
#historyPanel {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 1vw + 0.5rem, 16px);
  max-height: calc(100vh - 120px);
}

@media (max-width: 768px) {
  #historyPanel {
    max-height: 400px;
  }
}

#historyPanel h3 {
  margin: 0;
  font-size: clamp(1rem, 0.875rem + 0.625vw, 1.2rem);
  font-weight: 700;
  color: var(--text);
}

#historyList {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  scrollbar-width: thin;
}

#historyList::-webkit-scrollbar {
  width: 6px;
}

#historyList::-webkit-scrollbar-track {
  background: transparent;
}

#historyList::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 999px;
}

.history-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 20px 0;
  text-align: center;
}

.history-entry {
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--input-bg);
  padding: 12px;
  cursor: pointer;
  transition: border var(--transition-fast), transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.history-entry:hover {
  border-color: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.history-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.history-topic {
  font-weight: 500;
  color: var(--text);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.history-meta span {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
}

.history-timestamp {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.history-clear-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--input-bg);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), border var(--transition-fast),
    color var(--transition-fast);
  width: 100%;
}

.history-clear-btn:hover {
  background: var(--surface);
  border-color: var(--accent-soft);
  color: var(--text);
}

