:root { color-scheme: light; font-family: system-ui, sans-serif; color: #0f172a; background: #f8fafc; font-size: 16px; }
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.5; }
a { color: #2563eb; text-underline-offset: 3px; }
button, input, select { font: inherit; font-variant-numeric: tabular-nums; }
button, select, input:not([type=file]), .download { min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
[hidden] { display: none !important; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid #e2e8f0; }
.nav-inner { max-width: 1080px; margin: auto; height: 100%; padding: 0 16px; display: flex; align-items: center; gap: 20px; }
.brand { color: #0f172a; font-weight: 750; text-decoration: none; margin-right: auto; }
.nav-inner nav { display: flex; gap: 16px; }
.nav-inner nav a { display: inline-flex; align-items: center; min-height: 44px; font-size: .9rem; }
main { max-width: 1080px; margin: auto; padding: 16px; }
.breadcrumb { font-size: .85rem; color: #475569; margin-bottom: 8px; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.2; margin: 0 0 8px; letter-spacing: -.025em; }
.intro { margin: 0 0 20px; color: #475569; }
form, .result { min-width: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.dropzone { display: grid; justify-items: start; gap: 8px; border: 1px dashed #94a3b8; border-radius: 8px; background: #fff; padding: 18px; }
.dropzone.dragover { border-color: #2563eb; background: #eff6ff; }
.dropzone svg { width: 24px; height: 24px; color: #2563eb; }
.dropzone label { font-weight: 650; }
input[type=file] { width: 100%; max-width: 100%; min-height: 44px; font-size: 1rem; }
input::file-selector-button { font: inherit; min-height: 44px; background: #fff; border: 1px solid #94a3b8; border-radius: 5px; padding: 6px 10px; margin-right: 8px; color: #0f172a; cursor: pointer; }
.hint { font-size: .875rem; color: #475569; margin: 6px 0 12px; }
button, .download { border: 1px solid #94a3b8; border-radius: 6px; padding: 9px 14px; background: #fff; color: #0f172a; }
.primary, .download { background: #2563eb; border-color: #2563eb; color: #fff; font-weight: 650; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
#status { color: #475569; }
#error { color: #b91c1c; overflow-wrap: anywhere; }
.guide { border-top: 1px solid #e2e8f0; margin-top: 28px; padding-top: 8px; }
details { border-bottom: 1px solid #e2e8f0; padding: 12px 0; }
summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; }
details p { max-width: 75ch; color: #475569; }
footer { max-width: 1080px; margin: 24px auto; padding: 0 16px; color: #475569; font-size: .875rem; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
.option { margin: 14px 0; min-width: 0; }
.option label { display: block; font-weight: 650; margin-bottom: 6px; }
.option input:not([type=range]), .option select { width: 100%; max-width: 100%; border: 1px solid #94a3b8; border-radius: 6px; padding: 8px 10px; background: #fff; color: #0f172a; font-size: 1rem; }
.option input[type=range] { width: 100%; min-height: 44px; accent-color: #2563eb; margin: 0; }
.option output { font-variant-numeric: tabular-nums; font-weight: 700; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 4px 0; }
.check input { width: 22px; height: 22px; min-height: 22px; accent-color: #2563eb; margin: 0; }
.check label { font-weight: 650; }
.hint { overflow-wrap: anywhere; }
#file-info { font-variant-numeric: tabular-nums; }
.result { position: sticky; top: 16px; border-top: 2px solid #0f172a; padding: 16px 0; font-variant-numeric: tabular-nums; }
.result h2 { font-size: 1.15rem; margin: 0 0 8px; }
.result p { overflow-wrap: anywhere; margin: 8px 0; }
.previews { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin: 12px 0; }
.previews figure { margin: 0; min-width: 0; }
.previews figcaption { font-size: .875rem; font-weight: 650; color: #475569; margin-bottom: 4px; }
.frame { aspect-ratio: 4 / 3; border: 1px solid #e2e8f0; border-radius: 6px; background: #f1f5f9; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.frame img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; }
#result-info { color: #0f172a; font-size: .95rem; white-space: pre-line; }
.download { display: inline-flex; align-items: center; text-decoration: none; max-width: 100%; margin-top: 8px; }
.privacy { color: #475569; font-size: .875rem; margin-top: 16px; padding-top: 12px; border-top: 1px solid #e2e8f0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Batch Processing */
.batch-container { margin: 16px 0; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; padding: 14px; }
.batch-title { font-size: 1rem; font-weight: 700; margin: 0 0 10px; color: #0f172a; }
.batch-list { display: flex; flex-direction: column; gap: 8px; max-height: 380px; overflow-y: auto; }
.batch-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f8fafc; font-variant-numeric: tabular-nums; }
.batch-thumb { width: 48px; height: 48px; flex-shrink: 0; object-fit: contain; border: 1px solid #cbd5e1; border-radius: 4px; background: #fff; }
.batch-details { flex: 1; min-width: 0; }
.batch-name { font-weight: 600; font-size: .85rem; color: #0f172a; overflow-wrap: anywhere; }
.batch-meta { font-size: .78rem; color: #475569; margin-top: 2px; overflow-wrap: anywhere; }
.batch-status { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 6px; border-radius: 4px; margin-top: 3px; }
.batch-status.ready { color: #475569; background: #f1f5f9; }
.batch-status.processing { color: #1e40af; background: #dbeafe; }
.batch-status.success { color: #166534; background: #dcfce7; }
.batch-status.error { color: #991b1b; background: #fee2e2; }
.batch-item-action { flex-shrink: 0; }
.batch-item-action .download-item { font-size: .8rem; padding: 6px 10px; min-height: 44px; }
.batch-actions-global { margin-top: 12px; display: flex; gap: 8px; }
.batch-actions-global .download-all-btn { width: 100%; min-height: 44px; }

/* Resize Presets */
.preset-group { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.preset-btn { min-height: 44px; padding: 6px 12px; font-size: .875rem; font-weight: 600; border: 1px solid #94a3b8; border-radius: 6px; background: #fff; color: #0f172a; cursor: pointer; }
.preset-btn:hover { background: #f1f5f9; }
.preset-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }

/* Visual Crop Overlay */
.crop-wrapper { position: relative; display: inline-block; max-width: 100%; user-select: none; overflow: hidden; border-radius: 6px; background: #0f172a; }
.crop-wrapper img { display: block; max-width: 100%; max-height: 420px; width: auto; height: auto; pointer-events: none; }
.crop-box { position: absolute; border: 2px dashed #2563eb; box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.45); cursor: move; box-sizing: border-box; touch-action: none; outline: none; }
.crop-box:focus-visible { border-color: #ffffff; }
.crop-handle { position: absolute; width: 44px; height: 44px; touch-action: none; }
/* Keep the hit area inside the clipped image; the visible grip stays small. */
.crop-handle::after { content: ''; position: absolute; width: 14px; height: 14px; background: #2563eb; border: 2px solid #fff; border-radius: 2px; top: 15px; left: 15px; pointer-events: none; }
.crop-handle.handle-nw { top: 0; left: 0; cursor: nwse-resize; }
.crop-handle.handle-ne { top: 0; right: 0; cursor: nesw-resize; }
.crop-handle.handle-sw { bottom: 0; left: 0; cursor: nesw-resize; }
.crop-handle.handle-se { bottom: 0; right: 0; cursor: nwse-resize; }
.crop-handle.handle-n { top: 0; left: calc(50% - 22px); cursor: ns-resize; }
.crop-handle.handle-s { bottom: 0; left: calc(50% - 22px); cursor: ns-resize; }
.crop-handle.handle-w { top: calc(50% - 22px); left: 0; cursor: ew-resize; }
.crop-handle.handle-e { top: calc(50% - 22px); right: 0; cursor: ew-resize; }
.crop-handle:is(.handle-nw, .handle-n, .handle-ne)::after { top: 0; }
.crop-handle:is(.handle-sw, .handle-s, .handle-se)::after { top: auto; bottom: 0; }
.crop-handle:is(.handle-nw, .handle-w, .handle-sw)::after { left: 0; }
.crop-handle:is(.handle-ne, .handle-e, .handle-se)::after { left: auto; right: 0; }

/* Rotate Quick Actions */
.rotate-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.rotate-btn { min-height: 44px; padding: 8px 12px; font-size: .875rem; font-weight: 600; border: 1px solid #94a3b8; border-radius: 6px; background: #fff; color: #0f172a; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.rotate-btn:hover { background: #f1f5f9; }

/* Watermark 9-Grid Position Selector */
.grid-9-wrap { margin: 8px 0 12px; }
.grid-9 { display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); gap: 4px; }
.grid-pos-btn { width: 44px; height: 44px; min-height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; border: 1px solid #cbd5e1; border-radius: 4px; background: #fff; cursor: pointer; }
.grid-pos-btn:hover { background: #f1f5f9; }
.grid-pos-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.grid-pos-btn svg { width: 14px; height: 14px; pointer-events: none; }

@media (max-width: 700px) { .workspace { grid-template-columns: minmax(0, 1fr); gap: 16px; } .result { position: static; } .nav-inner { gap: 12px; } .nav-inner nav { gap: 10px; } .brand { font-size: .95rem; } main { padding-top: 12px; } .intro { margin-bottom: 14px; } }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
