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

:root {
  --accent: #60a5fa;
  --accent-solid: #3b82f6;
  --surface: rgba(255,255,255,0.05);
  --surface-hover: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-dim: #64748b;
  --panel-bg: #1e293b;
  --chrome-bg: #0f172a;
  --font-mono: "SFMono-Regular", Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  --ascii-font-size: 10px;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--chrome-bg);
  color: var(--text);
}

.app {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ========== Top Bar ========== */

.top-bar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  background: linear-gradient(135deg, #1e3a5f 0%, #1a2e4a 100%);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  z-index: 100;
  gap: 0.75rem;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.top-bar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex-shrink: 1;
}

.file-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.15);
}

.file-name {
  font-size: 0.78rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.font-size-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  min-width: 30px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Icon buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
  font-family: inherit;
}

.icon-btn:hover:enabled {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border-color: rgba(255,255,255,0.1);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.icon-btn.active {
  background: rgba(96,165,250,0.15);
  color: var(--accent);
  border-color: rgba(96,165,250,0.25);
}

.icon-btn-sm {
  width: 24px;
  height: 24px;
}

/* Export dropdown */
.export-dropdown {
  position: relative;
}

.export-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 4px;
  min-width: 170px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
}

.export-menu button {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

.export-menu button:hover {
  background: rgba(255,255,255,0.08);
}

/* ========== Settings Panel ========== */

.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.panel-backdrop.visible {
  opacity: 1;
}

.settings-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 340px;
  height: 100%;
  background: var(--panel-bg);
  border-right: 1px solid rgba(255,255,255,0.08);
  z-index: 400;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.settings-panel.open {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

/* Panel sections (details/summary) */
.panel-section {
  border-bottom: 1px solid var(--border);
}

.panel-section summary {
  padding: 0.7rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: color 0.15s;
}

.panel-section summary:hover {
  color: var(--text);
}

.panel-section summary::after {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s;
}

.panel-section[open] summary::after {
  transform: rotate(45deg);
}

.panel-section summary::-webkit-details-marker {
  display: none;
}

.section-body {
  padding: 0.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Panel drop zone (compact) */
.panel-drop-zone {
  border: 2px dashed rgba(96,165,250,0.3);
  border-radius: 8px;
  background: rgba(96,165,250,0.05);
  padding: 0.6rem 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.panel-drop-zone:hover {
  border-color: rgba(96,165,250,0.5);
  background: rgba(96,165,250,0.08);
}

.panel-drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(96,165,250,0.12);
}

.panel-drop-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Control elements */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.control-group > label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.slider-value {
  font-size: 0.78rem;
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--accent);
}

/* Range sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--panel-bg);
  box-shadow: 0 0 0 1px rgba(96,165,250,0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--panel-bg);
}

/* Inputs */
.num-input {
  width: 60px;
  padding: 0.3rem 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
  text-align: center;
}

.num-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(96,165,250,0.15);
}

select {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(96,165,250,0.15);
}

select option {
  background: var(--panel-bg);
  color: var(--text);
}

.text-input {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 0.82rem;
  font-family: var(--font-mono);
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(96,165,250,0.15);
}

/* Panel export buttons */
.export-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.panel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  transition: all 0.15s ease;
}

.panel-btn:hover:enabled {
  background: rgba(96,165,250,0.12);
  border-color: rgba(96,165,250,0.25);
  color: var(--accent);
}

.panel-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.panel-btn svg {
  flex-shrink: 0;
}

/* ========== Main Area ========== */

.main-area {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* Landing state */
.landing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(30,58,95,0.4) 0%, var(--chrome-bg) 70%);
}

.landing-drop-zone {
  text-align: center;
  padding: 3rem 4rem;
  border: 2px dashed rgba(96,165,250,0.25);
  border-radius: 20px;
  background: rgba(96,165,250,0.03);
  cursor: pointer;
  transition: all 0.3s ease;
  max-width: 480px;
  width: 100%;
}

.landing-drop-zone:hover {
  border-color: rgba(96,165,250,0.45);
  background: rgba(96,165,250,0.06);
  transform: translateY(-2px);
}

.landing-drop-zone.dragover {
  border-color: var(--accent);
  background: rgba(96,165,250,0.1);
  transform: translateY(-2px);
  box-shadow: 0 8px 40px rgba(96,165,250,0.15);
}

.landing-icon {
  color: var(--accent);
  opacity: 0.5;
  margin-bottom: 1rem;
}

.landing-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.landing-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.landing-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Loaded state */
.loaded {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ASCII container — theme scoped here */
.ascii-container {
  flex: 1;
  overflow: auto;
  background: #ffffff;
  min-height: 0;
}

#asciiOutput {
  margin: 0;
  padding: 0.75rem 1rem;
  white-space: pre;
  font-family: var(--font-mono);
  font-size: var(--ascii-font-size);
  line-height: 1.05;
  color: #000000;
}

/* Theme modifiers — scoped to .ascii-container */
.ascii-container.theme-light {
  background: #ffffff;
}
.ascii-container.theme-light #asciiOutput {
  color: #111827;
}

.ascii-container.theme-dark {
  background: #020617;
}
.ascii-container.theme-dark #asciiOutput {
  color: #22c55e;
}

.ascii-container.theme-amber {
  background: #020204;
}
.ascii-container.theme-amber #asciiOutput {
  color: #f59e0b;
}

.ascii-container.theme-paper {
  background: #f5f0e6;
}
.ascii-container.theme-paper #asciiOutput {
  color: #374151;
}

/* ========== Source Image Overlay ========== */

.source-overlay {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 240px;
  background: var(--panel-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
  overflow: hidden;
}

.source-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.source-overlay img {
  width: 100%;
  display: block;
}

/* ========== Responsive ========== */

@media (max-width: 700px) {
  .settings-panel {
    width: 100%;
  }

  .top-bar-title {
    font-size: 0.85rem;
  }

  .file-info {
    display: none;
  }

  .landing-drop-zone {
    padding: 2rem 1.5rem;
    margin: 0 1rem;
  }

  .landing-title {
    font-size: 1.1rem;
  }

  .source-overlay {
    width: 160px;
    bottom: 0.5rem;
    right: 0.5rem;
  }
}

@media (max-width: 400px) {
  .font-size-label {
    display: none;
  }
}
