:root {
  --bg: #f6f7f5; --surface: #ffffff; --surface2: #eef1ee; --text: #17201d; --muted: #5b6862;
  --line: #d9dfdb; --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #d5efeb;
  --high: #b42318; --high-soft: #fde7e4; --med: #a15c07; --med-soft: #fdf0d9; --low: #476073; --low-soft: #e6eef4;
  --ok: #157f3c; --ok-soft: #dcf3e4;
  --sea: #dce9f0; --land: #f4f1e8; --landline: #a9b2ac; --grat: #c8d6de; --pin: #d92d20;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171e1b; --surface2: #1f2824; --text: #e6ece9; --muted: #9aa8a1;
  --line: #2c3833; --accent: #2dd4bf; --accent-ink: #062a26; --accent-soft: #123b36;
  --high: #ff8a7a; --high-soft: #3a1714; --med: #f5b94a; --med-soft: #36270c; --low: #9fbad0; --low-soft: #1c2a35;
  --ok: #5ee08f; --ok-soft: #12301f;
  --sea: #15232b; --land: #24302b; --landline: #4b5a53; --grat: #1e313b; --pin: #ff6b5e;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 6px 10px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.backlink { text-decoration: none; color: var(--muted); }
.sep { color: var(--line); }
.chip { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
:root[data-theme="dark"] .chip { color: var(--accent); }
.iconbtn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; min-width: 36px; height: 36px; font-size: 1.05rem; cursor: pointer; }
.iconbtn:hover { background: var(--surface2); }

main { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.hero { padding: 36px 0 20px; text-align: center; }
.lede { max-width: 640px; margin: 0 auto 22px; color: var(--muted); font-size: 1.05rem; }
.dropzone { max-width: 720px; margin: 0 auto; padding: 38px 16px; border: 2px dashed var(--line); border-radius: 18px; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-main { font-size: 1.25rem; font-weight: 600; margin: 0 0 4px; }
.dz-sub { margin: 0; color: var(--muted); }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }
.examples { margin: 16px auto 0; color: var(--muted); max-width: 720px; }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; }
.btn:hover:not(:disabled) { background: var(--surface2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.workspace { padding: 8px 0 24px; }
.summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.summary-text { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.summary-text b { font-size: 1.05rem; }
.summary-actions { display: flex; gap: 8px; }
.stat { font-size: .9rem; color: var(--muted); }
.stat.bad { color: var(--high); font-weight: 600; }

.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.filelist { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; padding: 2px; }
.fileitem { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; align-items: center; text-align: left; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; font: inherit; width: 100%; }
.fileitem[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.fileitem img, .fileitem .noimg { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; background: var(--surface2); display: block; }
.fileitem .fname { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fileitem .fsub { font-size: .78rem; color: var(--muted); }

.detail { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.detail-head { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 16px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.preview-wrap { width: 180px; height: 135px; border-radius: 8px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; }
.preview-wrap img { max-width: 100%; max-height: 100%; display: block; }
.detail-meta h2 { word-break: break-word; margin-bottom: 4px; }
.detail-meta p { margin: 0 0 6px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .8rem; font-weight: 700; }
.badge.high { background: var(--high-soft); color: var(--high); }
.badge.medium { background: var(--med-soft); color: var(--med); }
.badge.low { background: var(--low-soft); color: var(--low); }
.badge.none { background: var(--ok-soft); color: var(--ok); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.flags { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.flag { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px; border-radius: 10px; background: var(--surface2); }
.flag .lvl { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 6px; text-align: center; }
.flag.high .lvl { background: var(--high-soft); color: var(--high); }
.flag.medium .lvl { background: var(--med-soft); color: var(--med); }
.flag.low .lvl { background: var(--low-soft); color: var(--low); }
.flag b { display: block; }
.flag span.d { color: var(--muted); font-size: .9rem; word-break: break-word; }
.flags .none { padding: 10px; border-radius: 10px; background: var(--ok-soft); color: var(--ok); font-weight: 600; }

.mapctl { display: flex; gap: 6px; }
.mapbox { height: 340px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); touch-action: none; }
.worldmap { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
.worldmap:active { cursor: grabbing; }
.map-sea { fill: var(--sea); }
.map-land { fill: var(--land); stroke: var(--landline); stroke-linejoin: round; }
.map-grat { fill: none; stroke: var(--grat); }
.map-pin circle:first-child { fill: var(--pin); stroke: #fff; }
.map-pin .map-ring { fill: none; stroke: var(--pin); opacity: .45; }
.map-pin { cursor: pointer; }
.mapinfo { margin: 10px 0 4px; font-weight: 600; }

.thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.thumbs figure { margin: 0; background: var(--surface2); border-radius: 8px; padding: 8px; text-align: center; }
.thumbs img { max-width: 100%; max-height: 220px; display: block; margin: 0 auto 6px; border-radius: 4px; }
.thumbs figcaption { font-size: .82rem; color: var(--muted); }

.fieldtools { display: flex; gap: 10px; align-items: center; }
.fieldtools input[type="search"] { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; padding: 7px 10px; font: inherit; width: 180px; max-width: 100%; }
.fgroup { margin-top: 12px; }
.fgroup-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 4px; }
.fgroup-head h4 { margin: 0; font-size: .95rem; }
.fgroup-head .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.w3 { background: var(--high); } .dot.w2 { background: var(--med); } .dot.w1 { background: var(--low); } .dot.w0 { background: var(--line); }
.frow { display: grid; grid-template-columns: minmax(120px, 210px) minmax(0, 1fr); gap: 4px 14px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.frow:last-child { border-bottom: 0; }
.fname2 { font-weight: 600; font-size: .9rem; word-break: break-word; }
.fname2 .src { font-weight: 500; font-size: .7rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 4px; white-space: nowrap; }
.fval { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86rem; word-break: break-word; white-space: pre-wrap; }
.fval.empty { color: var(--muted); font-style: italic; font-family: inherit; }
.fexp { grid-column: 2; font-size: .82rem; color: var(--muted); }
.exports { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.nofields { color: var(--muted); padding: 8px 0; }

.clean { margin-top: 16px; }
.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.preset { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; background: var(--bg); }
.preset:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.preset span { display: flex; flex-direction: column; }
.preset small { color: var(--muted); font-size: .8rem; }
.keepgrid { border: 0; padding: 0; margin: 0 0 10px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 12px; }
.keepgrid[disabled] { opacity: .6; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.check.warn { color: var(--high); }
.opts, .method { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.reopts { display: flex; gap: 16px; flex-wrap: wrap; padding-left: 24px; }
.reopts select, .reopts input { vertical-align: middle; }
select { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 6px; padding: 4px 6px; font: inherit; }
.cleanbar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.results { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; padding: 10px; border-radius: 10px; background: var(--surface2); }
.result .rname { font-weight: 600; word-break: break-word; }
.result .rinfo { font-size: .85rem; color: var(--muted); }
.result .rinfo .good { color: var(--ok); font-weight: 600; }
.result .rinfo .bad { color: var(--high); font-weight: 600; }

.about { padding: 28px 0 10px; }
.aboutgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.aboutgrid div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.aboutgrid p { margin: 0; color: var(--muted); font-size: .92rem; }
@media (min-width: 901px) { .faq .aboutgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.foot { max-width: 1180px; margin: 0 auto; padding: 18px 16px 30px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .filelist { position: static; flex-direction: row; overflow-x: auto; max-height: none; }
  .fileitem { min-width: 210px; width: 210px; }
  .presets, .keepgrid, .aboutgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .detail-head { grid-template-columns: minmax(0, 1fr); }
  .preview-wrap { width: 100%; height: 180px; }
  .presets, .keepgrid, .aboutgrid, .thumbs { grid-template-columns: minmax(0, 1fr); }
  .frow { grid-template-columns: minmax(0, 1fr); }
  .fexp { grid-column: 1; }
  .mapbox { height: 260px; }
  .flag { grid-template-columns: minmax(0, 1fr); }
  .flag .lvl { justify-self: start; }
  .card-head { align-items: flex-start; }
  .fieldtools { width: 100%; }
  .fieldtools input[type="search"] { flex: 1; width: auto; }
}
