:root {
  color-scheme: light;
  --page: #f7f4ee;
  --surface: #fffdf9;
  --surface-soft: #fbf8f2;
  --surface-muted: #f3eee5;
  --line: #ded6ca;
  --line-strong: #c8bcae;
  --ink: #1f1d1a;
  --ink-soft: #58524b;
  --ink-muted: #8a8176;
  --accent: #9a7a3f;
  --accent-soft: #efe6d3;
  --success: #4d8b55;
  --danger: #b85545;
  --danger-soft: #fff3ef;
  --container-max: 1320px;
  --sidebar-width: clamp(320px, 30vw, 420px);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --font-display: Georgia, "Times New Roman", serif;
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --shadow: 0 24px 70px rgb(44 36 24 / 0.12), 0 3px 12px rgb(44 36 24 / 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background:
    radial-gradient(circle at 50% -10%, rgb(255 255 255 / 0.9), transparent 42rem),
    linear-gradient(180deg, #faf8f3 0%, var(--page) 100%);
  color: var(--ink);
  font-family: var(--font-ui);
}

body {
  min-height: 100vh;
  margin: 0;
  padding: clamp(18px, 3vw, 42px);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

:focus-visible {
  outline: 3px solid rgb(154 122 63 / 0.35);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  width: min(100%, var(--container-max));
  margin: 0 auto;
  overflow: clip;
  background: linear-gradient(180deg, var(--surface), var(--surface-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(24px, 3vw, 36px);
  border-bottom: 1px solid rgb(222 214 202 / 0.58);
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  flex: 0 0 auto;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(34px, 4vw, 48px);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.brand p {
  margin: 9px 0 0;
  color: var(--ink-muted);
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.privacy-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 9px 14px;
  color: var(--ink-soft);
  background: rgb(255 255 255 / 0.62);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  gap: clamp(18px, 2vw, 26px);
  padding: 0 clamp(22px, 3vw, 36px) clamp(22px, 3vw, 34px);
}

.workspace {
  display: grid;
  min-width: 0;
  gap: 18px;
}

.panel {
  min-width: 0;
  background: rgb(255 253 249 / 0.86);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.7) inset;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 0;
}

.panel-heading h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.015em;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 25px;
  height: 25px;
  flex: 0 0 auto;
  color: white;
  background: var(--ink);
  border-radius: 50%;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
}

.import-panel,
.preview-panel {
  padding-bottom: 18px;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: clamp(160px, 20vw, 216px);
  margin: 18px;
  padding: 26px;
  color: var(--ink);
  text-align: center;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.58), rgb(250 246 239 / 0.58)),
    radial-gradient(circle at center, rgb(154 122 63 / 0.06), transparent 21rem);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.dropzone:hover,
.dropzone.is-dragover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.dropzone.is-dragover {
  transform: scale(1.005);
}

.dropzone-icon {
  width: 42px;
  height: 42px;
  margin-bottom: 10px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.dropzone strong {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 500;
}

.dropzone span,
.dropzone small {
  margin-top: 7px;
  color: var(--ink-soft);
  font-size: 14px;
}

.file-card {
  display: grid;
  grid-template-columns: 156px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  min-height: 92px;
  margin: 0 18px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.thumbnail-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--surface-muted);
  border: 1px solid rgb(31 29 26 / 0.1);
  border-radius: 8px;
}

.thumbnail-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail-wrap span {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 700;
}

.thumbnail-wrap.has-placeholder img {
  display: none;
}

.thumbnail-wrap.has-placeholder span {
  display: grid;
}

.file-name {
  margin: 0;
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.valid-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: white;
  background: var(--success);
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
}

.operation-message {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  padding: 15px 16px;
  background: var(--danger-soft);
  border: 1px solid #e4b5aa;
  border-radius: var(--radius-md);
}

.operation-message-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: white;
  background: var(--danger);
  border-radius: 50%;
  font-weight: 700;
}

.operation-message h2 {
  margin: 3px 0 0;
  font-size: 15px;
}

.operation-message p {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
}

.operation-message details {
  margin-top: 10px;
  font-size: 13px;
}

.operation-message summary {
  color: var(--ink-soft);
  cursor: pointer;
}

.operation-message pre {
  max-height: 180px;
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  color: var(--ink-soft);
  background: rgb(255 255 255 / 0.55);
  border: 1px solid rgb(184 85 69 / 0.2);
  border-radius: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.operation-message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.message-feedback {
  min-height: 0;
  color: var(--danger) !important;
}

.preview-heading {
  align-items: flex-start;
}

.preview-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px 16px;
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.preview-summary div {
  display: flex;
  gap: 4px;
}

.preview-summary dt::after {
  content: ":";
}

.preview-summary dd {
  margin: 0;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.ascii-frame {
  min-height: clamp(320px, 38vw, 430px);
  max-height: 65vh;
  margin: 18px 18px 0;
  overflow: auto;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.72), rgb(248 245 238 / 0.72)),
    repeating-linear-gradient(0deg, transparent 0 21px, rgb(31 29 26 / 0.025) 21px 22px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.ascii-output {
  width: max-content;
  min-width: 100%;
  min-height: inherit;
  margin: 0;
  padding: 18px;
  color: #272522;
  font-family: var(--font-mono);
  font-size: clamp(7px, 0.72vw, 10px);
  line-height: 0.95;
  letter-spacing: 0.01em;
  white-space: pre;
}

.ascii-output.is-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  white-space: pre-wrap;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 18px 18px 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 170px;
  min-height: 43px;
  padding: 10px 18px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-weight: 650;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.button:not(:disabled):hover {
  transform: translateY(-1px);
  background: white;
  border-color: var(--line-strong);
}

.button-primary {
  color: white;
  background: linear-gradient(180deg, #37332f, #1f1d1a);
  border-color: #1f1d1a;
  box-shadow: 0 8px 18px rgb(31 29 26 / 0.16);
}

.button-primary:not(:disabled):hover {
  background: linear-gradient(180deg, #423d38, #24211e);
  border-color: #1f1d1a;
}

.button-small {
  min-width: 0;
  min-height: 36px;
  padding: 7px 11px;
  font-size: 13px;
}

.workspace-status,
.local-footnote {
  margin: 13px 18px 0;
  color: var(--ink-muted);
  font-size: 13px;
  text-align: center;
}

.workspace-status {
  min-height: 1.4em;
  color: var(--ink-soft);
}

.workspace-status.is-success {
  color: var(--success);
}

.workspace-status.is-error {
  color: var(--danger);
}

.settings-panel {
  position: sticky;
  top: 24px;
  align-self: start;
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding-bottom: 18px;
}

.settings-heading {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.reset-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 4px 0;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  font-size: 14px;
}

.settings-form {
  padding: 0 18px;
}

.control {
  display: grid;
  gap: 10px;
  padding: 18px 0;
  border-bottom: 1px solid rgb(222 214 202 / 0.72);
}

.control > label,
.toggle-row label {
  font-weight: 650;
}

.control > label span {
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 400;
}

.range-row {
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr) auto 48px;
  align-items: center;
  gap: 10px;
}

.range-row-compact {
  grid-template-columns: minmax(90px, 1fr) 64px;
}

.range-row small {
  color: var(--ink-soft);
  white-space: nowrap;
}

input[type="range"] {
  width: 100%;
  min-width: 70px;
  accent-color: var(--ink);
}

.number-input,
select {
  height: 42px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.number-input {
  width: 48px;
  padding: 0 5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  appearance: textfield;
}

.number-input::-webkit-inner-spin-button {
  appearance: none;
}

.number-input-wide {
  width: 64px;
}

select {
  width: 100%;
  padding: 0 36px 0 12px;
}

[aria-invalid="true"] {
  border-color: var(--danger) !important;
}

.control-hint,
.field-message {
  margin: -3px 0 0;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.4;
}

.field-message:empty {
  display: none;
}

.field-message.is-valid {
  color: var(--success);
}

.field-message.is-error {
  color: var(--danger);
}

.toggle-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 18px 0;
  border-bottom: 1px solid rgb(222 214 202 / 0.72);
}

.toggle-row p {
  margin: 5px 0 0;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.4;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  background: #d8d1c7;
  border: 1px solid #cfc6ba;
  border-radius: 999px;
  transition: background 160ms ease;
}

.switch span::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgb(31 29 26 / 0.18);
  content: "";
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: #2d2a26;
  border-color: #2d2a26;
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.switch input:focus-visible + span {
  outline: 3px solid rgb(154 122 63 / 0.35);
  outline-offset: 3px;
}

.settings-note {
  display: flex;
  gap: 12px;
  margin: 20px 18px 0;
  padding: 15px;
  color: var(--ink-soft);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.5;
}

.settings-note > span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  color: var(--accent);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-weight: 700;
}

.settings-note p {
  margin: 0;
}

@media (max-width: 1060px) {
  body {
    padding: 18px;
  }

  .app-layout {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    position: static;
    max-height: none;
  }
}

@media (max-width: 720px) {
  body {
    padding: 0;
    background: var(--surface);
  }

  .app-shell {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 15px 16px;
    background: rgb(255 253 249 / 0.93);
    backdrop-filter: blur(14px);
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 28px;
    font-size: 26px;
  }

  .brand h1 {
    font-size: 23px;
    letter-spacing: -0.02em;
  }

  .brand p,
  .privacy-badge {
    display: none;
  }

  .app-layout {
    gap: 14px;
    padding: 0 12px 18px;
  }

  .panel-heading {
    padding: 15px 14px 0;
  }

  .panel-heading h2 {
    font-size: 17px;
  }

  .step {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }

  .dropzone {
    min-height: 132px;
    margin: 14px;
    padding: 18px;
  }

  .dropzone-icon {
    width: 34px;
    height: 34px;
  }

  .dropzone strong {
    font-size: 15px;
  }

  .dropzone span,
  .dropzone small {
    font-size: 12px;
  }

  .file-card {
    grid-template-columns: 72px minmax(0, 1fr) auto;
    min-height: 68px;
    margin: 0 14px;
    gap: 10px;
  }

  .file-name,
  .file-meta {
    font-size: 12px;
  }

  .preview-heading {
    display: block;
  }

  .preview-summary {
    justify-content: flex-start;
    margin: 12px 0 0 34px;
  }

  .ascii-frame {
    min-height: 240px;
    margin: 14px 14px 0;
  }

  .ascii-output {
    padding: 12px;
    font-size: 6.5px;
    line-height: 0.96;
  }

  .ascii-output.is-placeholder {
    font-size: 13px;
  }

  .action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: 14px 14px 0;
  }

  .button {
    min-width: 0;
    min-height: 40px;
    padding: 9px 10px;
    font-size: 13px;
  }

  .workspace-status,
  .local-footnote {
    margin-right: 14px;
    margin-left: 14px;
    font-size: 12px;
  }

  .settings-form {
    padding: 0 14px;
  }

  .settings-note {
    margin: 16px 14px 0;
  }

  .operation-message {
    margin: 0 2px;
  }
}

@media (max-width: 430px) {
  .range-row {
    grid-template-columns: minmax(70px, 1fr) 52px;
  }

  .range-row small {
    display: none;
  }

  .number-input {
    width: 52px;
  }

  .preview-summary div:nth-child(3),
  .preview-summary div:nth-child(4) {
    display: none;
  }

  .action-row {
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
