@font-face { font-family: "DB Helvethaica X"; src: url("assets/fonts/DBHelvethaicaX-Cond.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "DB Helvethaica X"; src: url("assets/fonts/DBHelvethaicaX-MedCond.ttf") format("truetype"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "DB Helvethaica X"; src: url("assets/fonts/DBHelvethaicaX-BdCond.ttf") format("truetype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "DB Helvethaica X"; src: url("assets/fonts/DBHelvethaicaX-BlkCond.ttf") format("truetype"); font-weight: 900; font-style: normal; font-display: swap; }

:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f4f5f7;
  --panel-2: #eceef1;
  --panel-3: #dde1e6;
  --line: #d7dce2;
  --line-soft: #e8ebef;
  --text: #111315;
  --muted: #5b6470;
  --gold: #1e46b7;
  --gold-strong: #123069;
  --purple: #f14000;
  --green: #128a4d;
  --red: #dc2626;
  --radius: 12px;
  --shadow: 0 18px 40px rgba(17, 19, 21, .12);
  --canvas: #0b0f0d;
  --canvas-2: #050807;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; font-size: 18px; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: "DB Helvethaica X", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.35; }
body { overflow: hidden; }
button, input, select { font: inherit; }
button, label[for] { -webkit-tap-highlight-color: transparent; }
.mobile-label, .mobile-only { display: none; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; background: radial-gradient(circle at 70% 10%, rgba(30,70,183,.05), transparent 30%), var(--bg); }
.topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 18px; padding: 8px 20px; border-bottom: 1px solid var(--line-soft); background: rgba(255,255,255,.96); position: relative; z-index: 4; }
.score-strip { display: grid; grid-template-columns: repeat(3, minmax(80px, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-width: 0; }
.score-card { min-width: 0; min-height: 96px; padding: 8px 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(180deg, #ffffff, #f6f7f9); border-right: 1px solid var(--line-soft); text-align: center; }
.score-card:last-child { border-right: 0; }
.score-card.ratio-score strong { font-size: 42px; }
.score-card.primary { background: linear-gradient(180deg, rgba(30,70,183,.10), rgba(30,70,183,.03)); }
.score-card span { color: var(--muted); font-size: 22px; font-weight: 800; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.score-card strong { color: var(--gold-strong); font-size: 56px; line-height: 1; }
.score-card small { color: #8891a0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.top-actions { display: flex; gap: 10px; }

.button, .tool-button, .panel-tab, .icon-button { border: 1px solid var(--line); color: var(--text); background: #fff; cursor: pointer; transition: border-color .16s, background .16s, transform .08s, color .16s; }
.button:hover, .tool-button:hover, .panel-tab:hover { border-color: #b7c0cc; background: var(--panel); }
.button:active, .tool-button:active { transform: translateY(1px); }
.button { min-height: 58px; padding: 0 24px; border-radius: 9px; font-weight: 800; font-size: 22px; display: inline-flex; justify-content: center; align-items: center; text-decoration: none; }
.button.gold { color: #fff; border-color: var(--gold); background: linear-gradient(180deg, #2551c9, #1a3da3); }
.button.gold:hover { background: linear-gradient(180deg, #2d5bd6, #1e46b7); }
.button.subtle { background: var(--panel); }
.button.danger { border-color: #f1b9b9; color: #b91c1c; background: #fdf1f1; }
.button.full { width: 100%; }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; }
.canvas-section { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.canvas-toolbar { height: 76px; flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line-soft); background: var(--panel); overflow-x: auto; scrollbar-width: thin; }
.toolbar-group { display: flex; gap: 5px; }
.tool-button { min-height: 56px; padding: 0 18px; border-radius: 8px; font-size: 20px; font-weight: 800; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; }
.tool-button.active { border-color: var(--gold); color: #fff; background: var(--gold); }
.upload-button { cursor: pointer; }
.toolbar-divider { width: 1px; height: 28px; background: var(--line); flex: 0 0 auto; }

.mobile-editor-stage { flex: 1; min-height: 260px; display: grid; grid-template-columns: minmax(0, 1fr) 0; position: relative; overflow: hidden; background: var(--canvas); }
.mobile-editor-stage.dock-open { grid-template-columns: minmax(0, 1fr) 220px; }
.canvas-wrap { min-width: 0; min-height: 0; position: relative; overflow: hidden; background-color: var(--canvas); background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px); background-size: 24px 24px; touch-action: none; }
#editorCanvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.canvas-wrap.panning #editorCanvas { cursor: grabbing; }
.canvas-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; color: #9aa6ac; pointer-events: none; }
.canvas-empty.hidden { display: none; }
.canvas-empty .button { pointer-events: auto; margin-top: 8px; }
.empty-icon { font-size: 56px; color: var(--gold); opacity: .8; }
.canvas-empty h2 { margin: 0; font-size: 32px; color: #fff; }
.canvas-empty p { max-width: 440px; margin: 0 20px; font-size: 19px; }
.canvas-status, .zoom-badge { position: absolute; bottom: 12px; height: 42px; display: flex; align-items: center; padding: 0 14px; border: 1px solid rgba(255,255,255,.14); border-radius: 8px; background: rgba(11,15,13,.88); backdrop-filter: blur(8px); color: #c7cdd1; font-size: 17px; font-weight: 700; pointer-events: none; }
.canvas-status { left: 12px; }
.zoom-badge { right: 12px; color: #ff7a3d; }
.magnifier-canvas { position: absolute; width: 264px; height: 264px; border-radius: 50%; border: 2px solid var(--gold); box-shadow: 0 8px 22px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.08); background: var(--canvas-2); pointer-events: none; z-index: 6; opacity: 0; visibility: hidden; transition: opacity .08s ease; }
.magnifier-canvas.visible { opacity: 1; visibility: visible; }

.mobile-tool-dock { min-width: 0; height: 100%; overflow-x: hidden; overflow-y: auto; border-left: 1px solid var(--line); color: var(--text); background: #fff; box-shadow: -10px 0 26px rgba(17,19,21,.10); scrollbar-width: thin; overscroll-behavior: contain; z-index: 3; }
.dock-header { min-height: 60px; position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px; align-items: center; gap: 5px; padding: 8px; border-bottom: 1px solid var(--line-soft); background: rgba(255,255,255,.96); backdrop-filter: blur(10px); }
.dock-header > div { min-width: 0; text-align: center; }
.dock-header strong, .dock-header span { display: block; max-width: 100%; white-space: nowrap; }
.dock-header strong { color: var(--gold-strong); font-size: 17px; line-height: 1.5; letter-spacing: .02em; text-transform: uppercase; }
.dock-header span { margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.dock-back, .dock-close { width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--gold); background: #fff; cursor: pointer; font-size: 22px; line-height: 1; }
.dock-back[hidden] { visibility: hidden; display: block !important; pointer-events: none; }
.dock-view { min-width: 0; }
.dock-content { display: grid; gap: 16px; padding: 14px; }
.dock-hint { margin: 0; padding: 11px 12px 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.mobile-tool-dock .tool-menu-list { gap: 8px; padding: 10px; }
.mobile-tool-dock .tool-menu-item { cursor: pointer; }
.mobile-tool-dock .tool-menu-item.active { border-color: var(--gold); color: var(--gold-strong); background: rgba(30,70,183,.08); box-shadow: inset 0 0 0 1px rgba(30,70,183,.10); }
.mobile-tool-dock .quick-tool-grid { grid-template-columns: 1fr; }
.mobile-tool-dock .preset-list { padding: 10px; }
.mobile-tool-dock .preset-list button { cursor: pointer; }
.mobile-tool-dock .check-row { cursor: pointer; }
.mobile-tool-dock .color-control-row input[type="color"] { width: 46px; }

.measurement-bar { min-height: 98px; flex: 0 0 auto; display: grid; grid-template-columns: repeat(4, 150px) minmax(210px, 1fr); gap: 1px; border-top: 1px solid var(--line-soft); background: var(--line-soft); }
.measurement-item, .measurement-note { background: #fff; display: flex; flex-direction: column; justify-content: center; padding: 9px 16px; }
.measurement-item span { font-size: 15px; letter-spacing: .07em; color: var(--muted); font-weight: 800; }
.measurement-item strong { font-size: 28px; color: var(--gold-strong); }
.measurement-note { color: var(--muted); font-size: 18px; line-height: 1.4; }
.measurement-note.error { color: var(--red); }
.measurement-note.success { color: var(--green); }

.control-panel { min-height: 0; overflow: hidden; border-left: 1px solid var(--line-soft); background: var(--panel); display: flex; flex-direction: column; box-shadow: -15px 0 40px rgba(17,19,21,.06); }
.panel-tabs { flex: 0 0 auto; height: 76px; display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line-soft); }
.panel-tab { border: 0; border-right: 1px solid var(--line-soft); border-radius: 0; color: var(--muted); font-size: 36px; font-weight: 800; background: var(--panel); }
.panel-tab:last-child { border-right: 0; }
.panel-tab.active { color: var(--gold-strong); background: #fff; box-shadow: inset 0 -3px var(--gold); }
.panel-content { display: none; overflow-y: auto; padding: 20px; scrollbar-width: thin; }
.panel-content.active { display: block; }
.section-title { color: var(--gold-strong); font-size: 19px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 13px; }
.section-title.spaced { margin-top: 30px; }
.spaced-small { margin-top: 15px; }
.hint { margin: 11px 0 16px; color: var(--muted); font-size: 18px; line-height: 1.5; }
.control-row { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line-soft); }
.control-row.stacked { align-items: stretch; flex-direction: column; justify-content: center; gap: 8px; padding: 13px 0; }
.control-row label, .field-label { color: var(--text); font-size: 18px; font-weight: 700; }
.label-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
output { color: var(--gold-strong); font-size: 18px; font-weight: 800; }
input[type="range"] { width: 100%; accent-color: var(--gold); height: 8px; }
input[type="color"] { width: 48px; height: 38px; border: 1px solid var(--line); border-radius: 7px; background: none; padding: 2px; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check-row { min-height: 58px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line-soft); color: var(--text); font-size: 18px; font-weight: 700; }
.check-row input { accent-color: var(--gold); width: 24px; height: 24px; }
select, input[type="number"] { width: 100%; min-height: 60px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); padding: 0 14px; outline: none; font-size: 19px; line-height: 1.3; }
select:focus, input[type="number"]:focus { border-color: var(--gold); }
.field-label { display: block; margin: 13px 0 8px; }

#helpDialog { width: min(620px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--text); padding: 0; box-shadow: var(--shadow); }
#helpDialog::backdrop { background: rgba(17,19,21,.45); backdrop-filter: blur(4px); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid var(--line-soft); }
.dialog-header strong { display: block; font-size: 26px; }
.dialog-header span { display: block; color: var(--muted); font-size: 17px; margin-top: 4px; }
.icon-button { width: 44px; height: 44px; border-radius: 8px; font-size: 28px; }
#helpDialog ol { margin: 20px 30px 8px 40px; padding: 0; color: var(--text); font-size: 19px; line-height: 1.7; }
#helpDialog p { margin: 12px 20px 20px; color: var(--muted); font-size: 18px; line-height: 1.55; }
#helpDialog > .button { width: calc(100% - 40px); margin: 0 20px 20px; }

.mobile-actions-dialog, .mobile-sheet-dialog { width: min(420px, calc(100vw - 20px)); max-height: min(82dvh, 780px); overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--text); padding: 0; box-shadow: var(--shadow); }
.mobile-actions-dialog::backdrop, .mobile-sheet-dialog::backdrop, .history-dialog::backdrop { background: rgba(17,19,21,.5); backdrop-filter: blur(5px); }
.mobile-action-list { display: grid; gap: 9px; padding: 16px; }
.photo-source-dialog { overflow: hidden; }
.photo-source-options { display: grid; gap: 10px; padding: 16px; }
.photo-source-option { min-height: 100px; display: grid; grid-template-columns: 56px minmax(0, 1fr); align-items: center; gap: 15px; padding: 13px 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: #fff; text-align: left; cursor: pointer; }
.photo-source-option:hover { border-color: var(--gold); background: var(--panel); }
.photo-source-option:active { transform: translateY(1px); }
.photo-source-option > span:last-child { min-width: 0; }
.photo-source-option b, .photo-source-option small { display: block; }
.photo-source-option b { font-size: 20px; letter-spacing: .01em; text-transform: uppercase; }
.photo-source-option small { margin-top: 5px; color: var(--muted); font-size: 16px; line-height: 1.35; }
.photo-source-icon { width: 54px; height: 54px; position: relative; display: block; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.photo-source-icon.camera-icon::before { content: ""; width: 28px; height: 19px; position: absolute; left: 11px; top: 17px; border: 2px solid var(--gold); border-radius: 4px; }
.photo-source-icon.camera-icon::after { content: ""; width: 8px; height: 8px; position: absolute; left: 21px; top: 22px; border: 2px solid var(--gold); border-radius: 50%; box-shadow: -8px -11px 0 -3px var(--gold); }
.photo-source-icon.library-icon::before, .photo-source-icon.library-icon::after { content: ""; position: absolute; border: 2px solid var(--gold); border-radius: 3px; }
.photo-source-icon.library-icon::before { width: 25px; height: 30px; left: 11px; top: 10px; transform: rotate(-5deg); opacity: .55; }
.photo-source-icon.library-icon::after { width: 27px; height: 32px; left: 15px; top: 12px; background: linear-gradient(145deg, transparent 51%, rgba(30,70,183,.14) 52%); }

.camera-dialog { width: 100vw; height: var(--app-viewport-height, 100dvh); max-width: none; max-height: none; inset: 0; margin: 0; padding: 0; border: 0; overflow: hidden; color: #fff; background: #000; }
.camera-dialog::backdrop { background: #000; }
.camera-shell { width: 100%; height: 100%; min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; overflow: hidden; padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0); background: #000; }
.camera-header { min-height: 68px; z-index: 3; display: grid; grid-template-columns: 54px minmax(0, 1fr) 68px; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,.12); background: #0a0a0a; }
.camera-header-button { min-width: 50px; min-height: 50px; padding: 0 8px; border: 1px solid rgba(255,255,255,.18); border-radius: 11px; color: #fff; background: #1a1a1a; cursor: pointer; font-size: 28px; line-height: 1; }
.camera-header-button:active { transform: translateY(1px); }
.camera-header-button.camera-switch { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 20px; }
.camera-header-button.camera-switch b { color: #c7c7c7; font-size: 13px; text-transform: uppercase; }
.camera-title { min-width: 0; text-align: center; }
.camera-title strong, .camera-title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camera-title strong { color: #fff; font-size: 19px; letter-spacing: .04em; text-transform: uppercase; }
.camera-title span { margin-top: 3px; color: #9a9a9a; font-size: 14px; }
.camera-viewport { min-width: 0; min-height: 0; position: relative; overflow: hidden; background: radial-gradient(circle, #1a1a1a, #050505 70%); isolation: isolate; container-type: size; }
#cameraVideo { width: 100%; height: 100%; display: block; object-fit: cover; object-position: center; background: #050505; }
.camera-card-guide { width: min(calc(100% - 34px), 300px); height: auto; position: absolute; z-index: 2; left: 50%; top: 50%; aspect-ratio: 63 / 88; transform: translate(-50%, -50%); border: 1px dashed rgba(255,122,61,.85); border-radius: clamp(10px, 3vmin, 20px); box-shadow: 0 0 0 120vmax rgba(0,0,0,.6), 0 0 20px rgba(255,122,61,.18), inset 0 0 0 1px rgba(255,255,255,.1); pointer-events: none; }
@supports (width: 1cqh) {
  .camera-card-guide { width: min(calc(100cqw - 34px), 63cqh, 544px); }
}
.camera-guide-corner { width: clamp(24px, 8vmin, 42px); height: clamp(24px, 8vmin, 42px); position: absolute; border-color: #ff7a3d; border-style: solid; filter: drop-shadow(0 0 5px rgba(255,122,61,.4)); }
.camera-guide-corner.top-left { left: -2px; top: -2px; border-width: 3px 0 0 3px; border-radius: clamp(10px, 3vmin, 20px) 0 0 0; }
.camera-guide-corner.top-right { right: -2px; top: -2px; border-width: 3px 3px 0 0; border-radius: 0 clamp(10px, 3vmin, 20px) 0 0; }
.camera-guide-corner.bottom-right { right: -2px; bottom: -2px; border-width: 0 3px 3px 0; border-radius: 0 0 clamp(10px, 3vmin, 20px) 0; }
.camera-guide-corner.bottom-left { left: -2px; bottom: -2px; border-width: 0 0 3px 3px; border-radius: 0 0 0 clamp(10px, 3vmin, 20px); }
.camera-guide-label { position: absolute; left: 50%; top: 9px; transform: translateX(-50%); padding: 6px 11px; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; color: #fff; background: rgba(0,0,0,.55); font-size: 13px; font-weight: 900; letter-spacing: .08em; white-space: nowrap; }
.camera-status { min-height: 36px; margin: 0; padding: 7px 14px 5px; color: #c7c7c7; background: #0a0a0a; font-size: 16px; line-height: 1.4; text-align: center; }
.camera-status:empty { display: none; }
.camera-status[data-tone="error"] { color: #ff8a8a; }
.camera-status[data-tone="success"] { color: #5fd68f; }
.camera-controls { min-height: 108px; z-index: 3; display: grid; grid-template-columns: 88px minmax(84px, 1fr) 88px; align-items: center; gap: 8px; padding: 9px 16px 11px; border-top: 1px solid rgba(255,255,255,.1); background: #0a0a0a; }
.camera-library-button { width: 80px; min-height: 70px; justify-self: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 1px solid rgba(255,255,255,.16); border-radius: 11px; color: #e2e2e2; background: #1a1a1a; cursor: pointer; }
.camera-library-button span { color: #ff7a3d; font-size: 25px; line-height: 1; }
.camera-library-button b { font-size: 13px; text-transform: uppercase; }
.camera-capture-button { min-width: 100px; min-height: 88px; justify-self: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 0; color: #fff; background: transparent; cursor: pointer; }
.camera-capture-button > span { width: 62px; height: 62px; display: block; position: relative; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0,0,0,.6); }
.camera-capture-button > span::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: linear-gradient(180deg, #ff8a52, #e85f1f); }
.camera-capture-button:active > span::after { transform: scale(.92); }
.camera-capture-button b { font-size: 13px; letter-spacing: .02em; text-transform: uppercase; }
.camera-header-button:disabled, .camera-library-button:disabled, .camera-capture-button:disabled { cursor: not-allowed; opacity: .42; }
.camera-control-spacer { width: 80px; }
.tool-menu-list { display: grid; gap: 8px; padding: 13px; }
.tool-menu-item { min-height: 58px; display: grid; grid-template-columns: 36px minmax(0, 1fr); align-items: center; column-gap: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: #fff; text-align: left; }
.tool-menu-item > span { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; line-height: 1; padding-top: 0.12em; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; color: var(--gold-strong); font-size: 15px; font-weight: 900; }
.tool-menu-item b { display: flex; align-items: center; height: 100%; padding-top: 0.12em; box-sizing: border-box; font-size: 16px; font-weight: 800; text-transform: uppercase; white-space: nowrap; line-height: 1; }

.sheet-content { display: grid; gap: 16px; padding: 18px; }
.color-control-row label { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--text); font-size: 19px; font-weight: 800; }
.color-control-row input[type="color"] { width: 66px; height: 42px; }
.sheet-range { display: grid; gap: 11px; }
.sheet-range > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-range label { color: var(--text); font-size: 18px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.sheet-range output { font-size: 19px; }
.sheet-range input[type="range"] { min-height: 34px; }
.quick-tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; padding: 16px; }
.quick-tool-grid button { min-height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: #fff; }
.quick-tool-grid button span { color: var(--gold-strong); font-size: 21px; font-weight: 900; }
.quick-tool-grid button b { font-size: 17px; }
.quick-tool-grid button.primary { border-color: var(--gold); color: #fff; background: var(--gold); }
.quick-tool-grid button.primary span { color: #fff; }
.preset-list { display: grid; gap: 10px; padding: 16px; }
.preset-list button { min-height: 66px; padding: 0 18px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: #fff; font-size: 19px; font-weight: 900; text-align: left; text-transform: uppercase; }
.preset-list button.active { border-color: var(--gold); color: var(--gold-strong); background: rgba(30,70,183,.08); }
.overlay-sheet { gap: 0; }

.history-dialog { width: min(760px, calc(100vw - 18px)); max-height: 92dvh; overflow: auto; border: 1px solid var(--line); border-radius: 18px; background: #fff; color: var(--text); padding: 0; box-shadow: var(--shadow); }
.history-screen { display: grid; gap: 18px; padding: 20px; }
.history-screen.hidden { display: none; }
.history-header { min-height: 52px; display: grid; grid-template-columns: 108px minmax(0, 1fr) 108px; align-items: center; gap: 8px; }
.history-header strong { font-size: 24px; text-align: center; text-transform: uppercase; letter-spacing: .02em; }
.history-header button { min-height: 50px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--panel); font-size: 18px; }
.storage-card { display: grid; gap: 10px; padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); }
.storage-card > div { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 18px; }
.storage-card strong { color: var(--gold-strong); }
.storage-card progress { width: 100%; height: 9px; accent-color: var(--gold); }
.history-items { display: grid; gap: 11px; }
.history-item { display: grid; grid-template-columns: 30px 92px minmax(0, 1fr) 88px; gap: 13px; align-items: center; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.history-item input { width: 24px; height: 24px; accent-color: var(--gold); }
.history-item img { width: 92px; height: 116px; border: 1px solid var(--line); border-radius: 8px; object-fit: cover; background: var(--panel); }
.history-item-info { min-width: 0; }
.history-item-info button { width: 100%; padding: 0; border: 0; color: var(--text); background: transparent; font-size: 18px; font-weight: 900; text-align: left; overflow-wrap: anywhere; }
.history-item-info small { display: block; margin-top: 7px; color: var(--muted); font-size: 15px; line-height: 1.45; }
.history-item-actions { display: grid; gap: 9px; }
.history-item-actions button { min-height: 44px; border: 1px solid var(--line); border-radius: 8px; color: var(--gold-strong); background: var(--panel); font-size: 15px; }
.history-item-actions button.danger { color: var(--red); }
.history-empty { margin: 20px 0; color: var(--muted); font-size: 19px; text-align: center; }
.history-delete-selected, .history-primary { min-height: 62px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--panel); font-size: 21px; font-weight: 900; text-transform: uppercase; }
.history-delete-selected:disabled { cursor: default; opacity: .38; }
.analysis-screen { max-width: 680px; margin: 0 auto; }
.analysis-thumbnail { width: min(100%, 440px); max-height: 26dvh; margin: 0 auto; border: 1px solid var(--line); border-radius: 11px; object-fit: contain; background: var(--panel); }
.analysis-score-grid { display: flex; justify-content: center; gap: 7px; }
.analysis-score-grid > div { width: 100%; max-width: 240px; min-height: 78px; }
.analysis-ratio-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.analysis-score-grid > div, .analysis-ratio-grid > div { min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 4px 2px; }
.analysis-score-grid span, .analysis-ratio-grid span { color: var(--muted); font-size: 11px; text-align: center; white-space: nowrap; }
.analysis-score-grid strong { color: var(--purple); font-size: 38px; font-weight: 900; }
.analysis-ratio-grid strong { color: var(--gold-strong); font-size: 18px; }
.analysis-save-status { margin: -4px 0 0; color: var(--muted); font-size: 17px; line-height: 1.35; text-align: center; }
.analysis-save-status:empty { display: none; }
.analysis-save-status[data-tone="success"] { color: var(--green); }
.analysis-save-status[data-tone="error"] { color: var(--red); }
.analysis-actions { display: flex; gap: 9px; }
.analysis-actions button { flex: 1 1 0; min-width: 0; min-height: 48px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--panel); font-size: 17px; font-weight: 800; padding: 0 6px; }
.analysis-actions button.danger { color: var(--red); }

.align-crop-canvas-wrap { display: flex; align-items: center; justify-content: center; background: #0b0f0d; border: 1px solid var(--line); border-radius: 11px; max-height: 52dvh; margin: 6px 0; padding: 16px 8px; box-sizing: border-box; overflow: hidden; touch-action: none; }
.align-crop-canvas-wrap canvas { max-width: 100%; max-height: calc(52dvh - 32px); display: block; cursor: grab; touch-action: none; }
.align-crop-canvas-wrap canvas:active { cursor: grabbing; }

.align-crop-controls { display: flex; flex-direction: column; gap: 10px; }
.align-slider-group { display: flex; flex-direction: column; gap: 2px; }
.align-slider-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.align-slider-title { display: flex; align-items: center; gap: 8px; }
.align-slider-label label { color: var(--text); font-size: 18px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.align-slider-label output { font-size: 19px; color: var(--gold-strong); }
.align-slider-group input[type="range"] { min-height: 34px; margin: 0; }
.align-apply-inline { flex: 0 0 auto; min-height: 40px; padding: 0 20px; border: 1px solid var(--gold); border-radius: 9px; background: var(--gold); color: #fff; font-size: 15px; font-weight: 900; text-transform: uppercase; }

@media (max-width: 1180px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .score-card small { display: none; }
  .score-card { padding-left: 6px; padding-right: 6px; }
  .workspace { grid-template-columns: minmax(0, 1fr) 340px; }
  .measurement-bar { grid-template-columns: repeat(4, 125px) minmax(170px, 1fr); }
}

@media (min-width: 861px) and (min-height: 601px), (min-width: 861px) and (pointer: fine) {
  .mobile-editor-stage.dock-open { grid-template-columns: minmax(0, 1fr) min(280px, 28vw); }
  .mobile-tool-dock { width: min(280px, 28vw); }
}

@media (max-width: 860px), (max-height: 600px) and (pointer: coarse) {
  html, body { height: 100%; min-height: 0; overflow: hidden; }
  body { overscroll-behavior: none; }
  .app-shell { width: 100%; height: var(--app-viewport-height, 100dvh); min-height: 0; overflow: hidden; padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0); }
  .topbar { display: none; }
  .workspace { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
  .canvas-section { flex: 1 1 auto; min-height: 0; overflow: hidden; }
  .canvas-toolbar { display: none; }

  .mobile-command-deck { flex: 0 0 auto; display: block; border-bottom: 1px solid var(--line-soft); background: #fff; }
  .mobile-appbar { flex: 0 0 auto; min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 5px 8px; }
  .mobile-quick-actions { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 5px; overflow-x: auto; scrollbar-width: none; }
  .mobile-quick-actions::-webkit-scrollbar { display: none; }
  .mobile-quick-button { flex: 0 0 42px; width: 42px; min-height: 24px; padding: 0.15em 3px 0; box-sizing: border-box; display: flex; align-items: center; justify-content: center; line-height: 1; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-quick-button.primary { border-color: var(--gold); color: #fff; background: var(--gold); }
  .mobile-appbar-button { flex: 0 0 auto; min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--gold-strong); background: var(--panel); font-size: 13px; font-weight: 900; }
  .mobile-appbar-button:disabled, .mobile-quick-button:disabled { opacity: .42; cursor: not-allowed; }

  .mobile-metrics { flex: 0 0 auto; min-height: 72px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line-soft); background: var(--panel); }
  .mobile-metrics > div { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; border-right: 1px solid var(--line-soft); padding: 5px 3px; gap: 1px; }
  .mobile-metrics > div:last-child { border-right: 0; }
  .mobile-metrics span { color: var(--muted); font-size: 20px; line-height: 1.15; font-weight: 900; letter-spacing: .02em; }
  .mobile-metrics strong { max-width: 100%; color: var(--gold-strong); font-size: 30px; line-height: 1.1; white-space: nowrap; }
  .mobile-metrics .ratio strong { font-size: 22px; }
  .mobile-metrics .ott strong { color: var(--purple); font-size: 34px; }

  .mobile-editor-stage { flex: 1 1 0; height: auto; min-height: 0; }
  .mobile-editor-stage.dock-open { grid-template-columns: minmax(0, 1fr) clamp(90px, 26vw, 108px); }
  .mobile-tool-dock .dock-header { min-height: 36px; grid-template-columns: 24px minmax(0, 1fr) 24px; gap: 3px; padding: 4px; }
  .mobile-tool-dock .dock-header strong { font-size: 12px; }
  .mobile-tool-dock .dock-back, .mobile-tool-dock .dock-close { width: 24px; height: 26px; font-size: 14px; border-radius: 6px; }
  .mobile-tool-dock .tool-menu-list { gap: 4px; padding: 5px; }
  .mobile-tool-dock .tool-menu-item { min-height: 30px; grid-template-columns: 16px minmax(0, 1fr); column-gap: 4px; padding: 4px 5px; border-radius: 6px; }
  .mobile-tool-dock .tool-menu-item > span { width: 15px; height: 15px; border-radius: 4px; font-size: 8px; }
  .mobile-tool-dock .tool-menu-item b { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-tool-dock .dock-content { gap: 12px; padding: 10px 8px; }
  .mobile-tool-dock .dock-hint { padding: 9px 8px 0; font-size: 12px; }
  .mobile-tool-dock .sheet-range { gap: 7px; }
  .mobile-tool-dock .sheet-range label { font-size: 12px; }
  .mobile-tool-dock .sheet-range output { font-size: 13px; }
  .mobile-tool-dock .sheet-range input[type="range"] { min-height: 34px; }
  .mobile-tool-dock .quick-tool-grid { gap: 5px; padding: 7px; }
  .mobile-tool-dock .quick-tool-grid button { min-height: 40px; flex-direction: row; justify-content: flex-start; gap: 5px; padding: 0 8px; border-radius: 7px; }
  .mobile-tool-dock .quick-tool-grid button span { width: 20px; flex: 0 0 20px; font-size: 13px; text-align: center; }
  .mobile-tool-dock .quick-tool-grid button b { font-size: 12px; }
  .mobile-tool-dock .preset-list { gap: 5px; padding: 7px; }
  .mobile-tool-dock .preset-list button { min-height: 40px; padding: 0 9px; border-radius: 7px; font-size: 12px; }
  .mobile-tool-dock .check-row { min-height: 42px; gap: 8px; font-size: 13px; }
  .mobile-tool-dock .color-control-row label { min-height: 38px; font-size: 13px; }
  .mobile-tool-dock .color-control-row input[type="color"] { width: 40px; height: 32px; }
  .mobile-corner-strip[hidden] { display: none !important; }
  .mobile-corner-strip:not([hidden]) { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 7px 9px 5px; border-top: 1px solid rgba(255,255,255,.12); border-bottom: 1px solid rgba(255,255,255,.06); background: var(--canvas); }
  .mobile-corner-strip .sheet-range { min-width: 0; gap: 2px; }
  .mobile-corner-strip .sheet-range > div { gap: 5px; }
  .mobile-corner-strip label { color: #c7cdd1; font-size: 11px; }
  .mobile-corner-strip output { color: #ff7a3d; font-size: 12px; }
  .mobile-corner-strip input[type="range"] { width: 100%; min-width: 0; min-height: 30px; }
  .canvas-empty { gap: 6px; }
  .empty-icon { font-size: 38px; }
  .canvas-empty h2 { font-size: 20px; }
  .canvas-empty p { font-size: 14px; }

  .measurement-bar { min-height: 40px; display: block; border-top: 1px solid var(--line-soft); background: #fff; }
  .measurement-item { display: none; }
  .measurement-note { min-height: 40px; padding: 6px 12px; color: var(--muted); background: #fff; font-size: 13px; text-align: center; }
  .measurement-note.success { display: none; }

  .mobile-panel-toggle, .control-panel { display: none !important; }

  select, input[type="number"] { min-height: 48px; font-size: 15px; }
  .field-label, .control-row label { font-size: 14px; }
  .section-title { font-size: 15px; }
}

@media (max-width: 560px) {
  .mobile-appbar { padding-left: 7px; padding-right: 7px; }
  .mobile-metrics strong { font-size: 30px; }
  .mobile-metrics .ratio strong { font-size: 22px; }
  .mobile-metrics .ott strong { font-size: 34px; }
  .mobile-tool-dock .dock-header span { display: none; }
  .canvas-status, .zoom-badge { bottom: 8px; height: 34px; padding: 0 11px; font-size: 14px; }
  .canvas-status { left: 8px; max-width: calc(100% - 100px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .zoom-badge { right: 8px; }
  .history-dialog { width: calc(100vw - 10px); max-height: calc(var(--app-viewport-height, 100dvh) - 10px); border-radius: 14px; }
  .history-screen { gap: 14px; padding: 15px; }
  .history-header { grid-template-columns: 84px minmax(0, 1fr) 84px; }
  .history-header strong { font-size: 18px; }
  .history-item { grid-template-columns: 28px 72px minmax(0, 1fr) 68px; gap: 9px; padding: 10px; }
  .history-item img { width: 72px; height: 94px; }
  .history-item-info button { font-size: 16px; }
  .history-item-info small { font-size: 13px; }
  .history-item-actions button { font-size: 13px; }
  .analysis-actions { flex-wrap: wrap; }
  .analysis-actions button { flex: 1 1 calc(50% - 5px); }
}

@media (max-height: 650px) and (orientation: portrait) {
  .camera-header { min-height: 58px; padding-top: 4px; padding-bottom: 4px; }
  .camera-header-button { min-width: 44px; min-height: 44px; }
  .camera-controls { min-height: 88px; padding-top: 5px; padding-bottom: 6px; }
  .camera-library-button { min-height: 58px; }
  .camera-capture-button { min-height: 72px; }
  .camera-capture-button > span { width: 52px; height: 52px; }
  .camera-card-guide { width: min(calc(100% - 34px), 290px); }
  @supports (width: 1cqh) {
    .camera-card-guide { width: min(calc(100cqw - 34px), 64cqh, 500px); }
  }
}

@media (orientation: landscape) and (max-height: 600px) {
  .camera-shell { grid-template-columns: 70px minmax(0, 1fr) 86px; grid-template-rows: minmax(0, 1fr); }
  .camera-header { min-width: 0; min-height: 0; grid-column: 1; grid-row: 1; grid-template-columns: 1fr; grid-template-rows: 42px minmax(0, 1fr) 46px; gap: 5px; padding: 7px; border-right: 1px solid rgba(255,255,255,.12); border-bottom: 0; }
  .camera-header-button { width: 42px; min-width: 42px; min-height: 42px; justify-self: center; }
  .camera-title { align-self: center; }
  .camera-title strong { font-size: 14px; line-height: 1.25; white-space: normal; }
  .camera-title span { display: none; }
  .camera-viewport { grid-column: 2; grid-row: 1; }
  .camera-card-guide { width: min(calc(100% - 20px), 60vmin, 280px); height: auto; max-width: none; }
  @supports (width: 1cqh) {
    .camera-card-guide { width: min(calc(100cqw - 20px), 66cqh, 380px); }
  }
  .camera-guide-label { top: 6px; padding: 5px 10px; }
  .camera-status { min-height: 0; z-index: 4; grid-column: 2; grid-row: 1; align-self: end; justify-self: center; max-width: calc(100% - 16px); margin: 0 0 5px; padding: 5px 12px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; background: rgba(0,0,0,.6); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .camera-controls { min-width: 0; min-height: 0; grid-column: 3; grid-row: 1; grid-template-columns: 1fr; grid-template-rows: 1fr auto auto 1fr; align-content: center; gap: 7px; padding: 8px; border-top: 0; border-left: 1px solid rgba(255,255,255,.1); }
  .camera-library-button { width: 64px; min-height: 50px; grid-row: 2; }
  .camera-capture-button { min-width: 68px; min-height: 64px; grid-row: 3; }
  .camera-capture-button > span { width: 50px; height: 50px; }
  .camera-control-spacer { display: none; }
}

@media (max-width: 860px), (max-height: 600px) and (pointer: coarse) {
  #helpDialog,
  .mobile-actions-dialog,
  .mobile-sheet-dialog,
  .history-dialog {
    top: calc(env(safe-area-inset-top, 0px) + 5px);
    right: calc(env(safe-area-inset-right, 0px) + 5px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 5px);
    left: calc(env(safe-area-inset-left, 0px) + 5px);
    max-width: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 10px);
    max-height: calc(var(--app-viewport-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 10px);
    margin: auto;
  }

  #helpDialog {
    width: min(600px, calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 10px));
  }

  .align-crop-dialog {
    height: calc(var(--app-viewport-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 10px);
    overflow: hidden;
  }
  .align-crop-screen { height: 100%; max-height: 100%; display: flex; flex-direction: column; overflow: hidden; padding: 10px 12px; gap: 8px; }
  .align-crop-screen .history-header { flex: 0 0 auto; min-height: 38px; }
  .align-crop-screen .history-header strong { font-size: 15px; }
  .align-crop-screen .history-header button { min-height: 34px; font-size: 13px; }
  .align-crop-canvas-wrap { flex: 1 1 auto; min-height: 0; max-height: none; margin: 0; }
  .align-crop-canvas-wrap canvas { max-height: 100%; }
  .align-crop-controls { flex: 0 0 auto; gap: 6px; }
  .align-slider-label label { font-size: 12px; }
  .align-slider-label output { font-size: 13px; }
  .align-slider-group input[type="range"] { min-height: 30px; }
  .align-apply-inline { min-height: 32px; padding: 0 14px; font-size: 12px; }

  .mobile-actions-dialog,
  .mobile-sheet-dialog {
    width: min(420px, calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 10px));
  }

  .history-dialog {
    width: min(760px, calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px) - 10px));
  }
}
