/**
 * ANSI Art Converter — Style
 * (c) 2026 Eric Bernstein
 */

/* --- Reset & Base --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #0a0a0e;
  color: #d0d0d0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}
a { color: #6699ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout Container --- */
header, main, footer {
  width: 100%;
  max-width: 900px;
  margin-inline: auto;
  padding-inline: 20px;
}

/* --- Header --- */
header { padding-block: 24px 16px; }
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
h1 {
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  color: #f0f0f0;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.subtitle {
  font-size: 0.9rem;
  color: #aaa;
  margin-block-start: 4px;
}

/* --- Language Switcher --- */
.lang-switch {
  flex-shrink: 0;
}
.lang-switch select {
  background: #16161e;
  color: #aaa;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 6px 32px 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath fill='%23aaa' stroke='%23aaa' stroke-width='0.5' d='M2 2l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
}
.lang-switch select:focus { outline: none; border-color: #5588ff; }

/* --- Upload Section --- */
.upload-section {
  margin-block-end: 20px;
}
.drop-zone {
  border: 2px dashed #333;
  border-radius: 16px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.over {
  border-color: #5588ff;
  background: rgba(85, 136, 255, 0.06);
}
.drop-zone:focus-visible {
  outline: 2px solid #5588ff;
  outline-offset: 2px;
}
.drop-icon {
  font-size: 2.5rem;
  margin-block-end: 8px;
  opacity: 0.6;
}
.drop-zone p { color: #aaa; font-size: 0.95rem; }
.drop-zone .hint { color: #777; font-size: 0.8rem; margin-block-start: 6px; }
input[type="file"] { display: none; }

/* --- Presets --- */
.presets-section { margin-block-end: 16px; }
.presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.preset {
  background: #14141c;
  border: 2px solid #252530;
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #ccc;
  font-family: inherit;
  font-size: inherit;
}
.preset:hover {
  border-color: #5588ff;
  background: #1a1a28;
}
.preset:active { transform: scale(0.97); }
.preset.active {
  border-color: #5588ff;
  background: rgba(85, 136, 255, 0.1);
  box-shadow: 0 0 12px rgba(85, 136, 255, 0.15);
}
.preset:focus-visible {
  outline: 2px solid #5588ff;
  outline-offset: 2px;
}
.preset-icon { font-size: 1.5rem; }
.preset-name { font-weight: 600; font-size: 0.9rem; }
.preset-desc { font-size: 0.72rem; color: #888; line-height: 1.3; }

/* --- Advanced Settings --- */
.settings-section { margin-block-end: 16px; }
.advanced {
  background: #12121a;
  border: 1px solid #252530;
  border-radius: 12px;
  overflow: hidden;
}
.advanced summary {
  padding: 12px 18px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #999;
  user-select: none;
  list-style: none;
}
.advanced summary::before {
  content: '▶';
  font-size: 1.1em;
  margin-inline-end: 8px;
  transition: transform 0.15s;
  display: inline-block;
}
.advanced[open] summary::before {
  transform: rotate(90deg);
}
.advanced summary:focus-visible {
  outline: 2px solid #5588ff;
  outline-offset: -2px;
}
.controls {
  padding: 12px 18px 18px;
}
.controls fieldset {
  border: none;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: #bbb;
}
.controls select {
  background: #1a1a24;
  color: #ddd;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 8px 36px 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 38px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23999' d='M1.5 1.5l4.5 5 4.5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
}
.controls select:focus { outline: none; border-color: #5588ff; }
.controls select:disabled { opacity: 0.3; cursor: default; }
.custom-input {
  background: #1a1a24;
  color: #ddd;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  min-height: 38px;
  width: 100%;
  font-family: inherit;
  margin-block-start: 4px;
}
.custom-input:focus { outline: none; border-color: #5588ff; }
.custom-input[hidden] { display: none; }
.custom-color {
  width: 100%;
  min-height: 38px;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 2px;
  background: #1a1a24;
  cursor: pointer;
  margin-block-start: 4px;
}
.custom-color:focus { outline: none; border-color: #5588ff; }
.custom-color[hidden] { display: none; }

/* --- Output Section --- */
.output-section { margin-block-end: 24px; }
.actions {
  display: flex;
  gap: 10px;
  margin-block-end: 12px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
  font-family: inherit;
}
.btn:focus-visible {
  outline: 2px solid #5588ff;
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.35; cursor: default; transform: none; box-shadow: none; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, #2255cc, #1a44aa);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { transform: scale(1.03); box-shadow: 0 4px 16px rgba(34, 85, 204, 0.35); }
.btn-primary:active:not(:disabled) { transform: scale(0.97); }

.btn-secondary {
  background: #1e1e2a;
  color: #aaa;
  border: 1px solid #333;
}
.btn-secondary:hover:not(:disabled) { border-color: #5588ff; color: #ddd; }
.btn-secondary:active:not(:disabled) { transform: scale(0.97); }

/* Status */
.status {
  font-size: 0.8rem;
  color: #aaa;
  margin-block-end: 10px;
  min-height: 1.2em;
}

/* Preview */
.preview-wrap {
  width: 100%;
  overflow-x: auto;
  position: relative;
  text-align: center;
}
.preview-wrap::after {
  content: '';
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  width: 30px;
  background: linear-gradient(to right, transparent, #0a0a0e);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.preview-wrap.scrollable::after { opacity: 1; }
#preview {
  background: #000;
  font-family: 'Courier New', 'Lucida Console', monospace;
  font-size: clamp(5px, 1.8vw, 10px);
  line-height: 1.0;
  padding: 10px;
  border-radius: 10px;
  white-space: pre;
  display: inline-block;
  letter-spacing: 0;
}
#preview:empty { display: none; }

/* --- Footer --- */
footer {
  margin-block-start: auto;
  padding-block: 24px;
  text-align: center;
  font-size: 0.75rem;
  color: #666;
  border-block-start: 1px solid #1a1a22;
}
.footer-links {
  margin-block-start: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.footer-links a { color: #6699ff; }
.footer-sep { color: #444; }

/* --- Loading Spinner --- */
.loading .drop-icon::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #5588ff;
  border-block-start-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-inline-start: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Hidden --- */
canvas { display: none; }

/* --- Responsive --- */
@media (max-width: 640px) {
  header { padding-block: 16px 12px; }
  .header-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .presets { grid-template-columns: repeat(2, 1fr); }
  .controls fieldset { flex-direction: column; }
  .controls label { width: 100%; }
  .controls select { width: 100%; }
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; text-align: center; }
  .drop-zone { padding: 30px 16px; }
}

@media (max-width: 380px) {
  .presets { grid-template-columns: 1fr 1fr; gap: 8px; }
  .preset { padding: 10px 6px; }
  .preset-desc { display: none; }
}

/* --- RTL --- */
[dir="rtl"] .advanced summary::before { content: '◀'; }
[dir="rtl"] .footer-links { direction: rtl; }
[dir="rtl"] .controls select,
[dir="rtl"] .lang-switch select {
  background-position: left 12px center;
  padding: 8px 12px 8px 36px;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0s !important;
    animation-duration: 0s !important;
  }
}
