:root {
  --bg: #FBF8F2;
  --card: #FFFFFF;
  --ink: #21211D;
  --muted: #625F57;
  --line: #E4DDD0;
  --field: #FFFFFF;
  --field-line: #D6CDBC;
  --accent: #08685C;
  --accent-hover: #05544A;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1F1EC;
  --ok: #1F6E43;
  --danger: #A4161A;
  --checker: #ECE7DD;
  --shadow: 0 1px 2px rgba(33, 33, 29, .05), 0 8px 24px -12px rgba(33, 33, 29, .14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14201D; --card: #1D2C28; --ink: #EEF3F1; --muted: #A9B8B3; --line: #2C3F3A;
    --field: #14201D; --field-line: #3A504A; --accent: #7ADBC4; --accent-hover: #9BE7D5; --accent-ink: #0E1A17;
    --accent-soft: #1F3B35; --ok: #7ADBC4; --danger: #FF8A80; --checker: #26352F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14201D; --card: #1D2C28; --ink: #EEF3F1; --muted: #A9B8B3; --line: #2C3F3A;
  --field: #14201D; --field-line: #3A504A; --accent: #7ADBC4; --accent-hover: #9BE7D5; --accent-ink: #0E1A17;
  --accent-soft: #1F3B35; --ok: #7ADBC4; --danger: #FF8A80; --checker: #26352F;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: 12px; top: -48px; z-index: 10; background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; }
.skip:focus { top: 12px; }

/* Header / hero */
.top { max-width: 1100px; margin: 0 auto; padding: 18px 24px 0; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 750; font-size: 19px; }
.brand-mark { width: 30px; height: 30px; }
.mark-bg { fill: var(--accent); }
.mark-fg { stroke: var(--bg); }
.theme-toggle {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer;
}
.theme-toggle svg { width: 20px; height: 20px; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

.hero { max-width: 1100px; margin: 0 auto; padding: 28px 24px 22px; }
.hero h1 { font-size: clamp(30px, 4.4vw, 46px); line-height: 1.08; letter-spacing: -.025em; font-weight: 800; }
.hero p { margin-top: 10px; font-size: clamp(17px, 1.6vw, 20px); color: var(--muted); max-width: 44ch; }

/* Layout */
.tool { max-width: 1100px; margin: 0 auto; padding: 0 24px 48px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card h2 { font-size: 18px; font-weight: 750; display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.num { width: 26px; height: 26px; border-radius: 99px; display: grid; place-items: center; font-size: 14px; background: var(--accent-soft); color: var(--accent); flex: none; }
.help { color: var(--muted); font-size: 15px; margin: -4px 0 12px; }
.result { position: sticky; top: 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1px solid transparent; font-weight: 650; font-size: 16px; cursor: pointer;
  touch-action: manipulation; transition: background-color .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--card); border-color: var(--field-line); }
.btn-ghost:hover { border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-big { width: 100%; min-height: 56px; font-size: 18px; margin-top: 14px; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--accent); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; min-height: 44px; }

/* Drop zone */
.drop { border: 2px dashed var(--field-line); border-radius: 12px; padding: 18px; transition: border-color .15s, background-color .15s; }
.drop.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.drop.has-photo { border-style: solid; border-color: var(--line); }
.drop-empty { text-align: center; }
.drop-art { width: 72px; height: auto; margin-bottom: 10px; }
.art-frame { fill: var(--card); stroke: var(--field-line); stroke-width: 2; }
.art-sun { fill: #F4C46A; }
.art-hill { stroke: var(--accent); }
.drop-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.hint { margin-top: 10px; color: var(--muted); font-size: 14px; }
kbd { font: 600 12px/1 var(--font); padding: 2px 6px; border-radius: 5px; border: 1px solid var(--line); border-bottom-width: 2px; background: var(--card); }
.photo-info { display: flex; gap: 14px; align-items: center; }
.thumb { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); flex: none; background: var(--checker); }
.photo-text { min-width: 0; }
.photo-name { font-weight: 650; overflow-wrap: anywhere; }
.photo-meta { color: var(--muted); font-size: 15px; }
.msg { margin-top: 10px; color: var(--danger); font-weight: 600; font-size: 15px; }

/* Size presets */
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.preset {
  min-height: 48px; border-radius: 12px; border: 1px solid var(--field-line); background: var(--field);
  font-weight: 700; font-size: 17px; cursor: pointer; touch-action: manipulation;
}
.preset:hover { border-color: var(--accent); }
.preset[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.other { margin-top: 14px; }
.other label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.other-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 10px; }
.other input, .other select {
  height: 48px; padding: 0 12px; font-size: 16px; border: 1px solid var(--field-line); border-radius: 12px; background: var(--field); min-width: 0;
}

/* Result */
.result-empty { color: var(--muted); }
.result-head { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.result-head.is-ok { color: var(--ok); }
.result-head.is-error { color: var(--danger); font-size: 17px; }
.result-sub { color: var(--muted); margin-top: 4px; }
/* After-download tip line: empty box takes no space but stays in the page for screen readers. */
.tip-box { margin: 0; font-size: 15px; color: var(--muted); }
.tip-box:not(:empty) { margin-top: 10px; }
.tip-box a { color: var(--accent); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.note { margin-top: 10px; font-size: 14px; color: var(--muted); background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 14px; color: var(--muted); }
.preview { border-radius: 12px; border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; min-height: 160px; }
.preview img { display: block; max-width: 100%; max-height: 52vh; height: auto; }
.checker {
  background-color: var(--card);
  background-image: conic-gradient(var(--checker) 25%, transparent 0 50%, var(--checker) 0 75%, transparent 0);
  background-size: 16px 16px;
}

/* Footer */
.foot { max-width: 1100px; margin: 0 auto; padding: 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; display: grid; gap: 6px; }
.foot-links { display: flex; gap: 8px; flex-wrap: wrap; }
.foot a { color: var(--accent); font-weight: 650; text-underline-offset: 3px; }

@media (max-width: 860px) {
  .tool { grid-template-columns: minmax(0, 1fr); padding: 0 16px 40px; gap: 16px; }
  .col { gap: 16px; }
  .result { position: static; }
  .top, .hero, .foot { padding-left: 16px; padding-right: 16px; }
  .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
