:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f27;
  --muted: #5f6673;
  --border: #d9dde4;
  --accent: #ff8c28;
  --accent-text: #1b1f27;
  --danger: #d33a3a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --surface: #1e222c;
    --surface-2: #272c38;
    --text: #e8eaf0;
    --muted: #9aa2b1;
    --border: #343a48;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { filter: brightness(1.05); border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.icon { padding: 4px 8px; line-height: 1; }
button.ghost { background: transparent; }
input[type="number"], input[type="text"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input[type="number"] { width: 110px; }
textarea { width: 100%; resize: vertical; }
input[type="range"] { width: 220px; max-width: 100%; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: inherit; text-decoration: none; }
.tagline { color: var(--muted); font-size: 13px; }

.layout { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100% - 50px); }
.sidebar { padding: 14px 10px; border-right: 1px solid var(--border); background: var(--surface); }
.nav-group { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 14px 10px 6px; }
.nav-item { display: block; padding: 7px 10px; border-radius: 8px; color: inherit; text-decoration: none; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.main { padding: 24px; max-width: 980px; width: 100%; display: flex; flex-direction: column; gap: 16px; }
.tool-head h1 { margin: 0 0 4px; font-size: 24px; }
.tool-head p { margin: 0; color: var(--muted); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  background: var(--surface);
  outline: none;
}
.dropzone.over, .dropzone:focus-visible { border-color: var(--accent); background: var(--surface-2); }
.dz-hint { color: var(--muted); font-size: 13px; margin-top: 6px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-size: 16px; }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.files li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size, .file-note { color: var(--muted); font-size: 13px; white-space: nowrap; }
.file-note { color: var(--accent); }

.options { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; padding-bottom: 8px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.progress { flex: 1 1 220px; min-width: 160px; height: 28px; position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.progress-bar { position: absolute; inset: 0; width: 0; background: var(--accent); opacity: .35; transition: width .15s; }
.progress-text { position: relative; display: block; line-height: 26px; padding: 0 10px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link.small { font-size: 12px; align-self: flex-start; }
.nav-select { display: none; margin-left: auto; max-width: 60vw; }
table.meta { border-collapse: collapse; font-size: 13px; }
table.meta th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 14px 3px 0; vertical-align: top; white-space: nowrap; }
table.meta td { padding: 3px 0; word-break: break-word; }
.copy { align-self: flex-start; margin-top: 6px; padding: 5px 10px; font-size: 13px; }
.preview { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.preview-wrap { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.stat { font-size: 13px; color: var(--muted); }

.crop-stage { position: relative; display: inline-block; max-width: 100%; }
.crop-stage canvas { display: block; max-width: 100%; touch-action: none; cursor: crosshair; border-radius: 8px; }

.md-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.md-grid textarea { min-height: 420px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.md-preview { width: 100%; height: 420px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

.skip-link { position: absolute; left: 8px; top: -40px; padding: 8px 12px; background: var(--accent); color: var(--accent-text); border-radius: 8px; z-index: 20; }
.skip-link:focus { top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.3); z-index: 10;
}
.toast-error { background: var(--danger); color: #fff; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .nav-select { display: block; }
  .tagline { display: none; }
  .main { padding: 16px; }
  .md-grid { grid-template-columns: 1fr; }
}

input[type="color"] { width: 48px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
input[type="text"] { width: 220px; max-width: 100%; }
.field > textarea { min-height: 320px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.md-grid .field { min-width: 0; }
