:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #17191c;
  --muted: #6b7179;
  --line: #dfe3e7;
  --soft: #f7f8f9;
  --red: #ed171f;
  --red-dark: #c90f16;
  --red-soft: #fff0f1;
  --shadow: 0 12px 34px rgba(20, 26, 33, 0.09);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button, input, select { font: inherit; }
button, label[for] { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; }

.topbar {
  height: 78px;
  padding: 0 max(24px, calc((100vw - 1440px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 8px; height: 38px; border-radius: 8px; background: var(--red); }
.brand h1 { margin: 0; font-size: 24px; line-height: 1.1; letter-spacing: -0.03em; }
.brand p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.top-actions { display: flex; gap: 8px; }
.icon-action {
  min-width: 58px;
  display: grid;
  grid-template-columns: 23px auto;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 650;
  font-size: 14px;
  cursor: pointer;
}

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(360px, .75fr);
  gap: 20px;
  align-items: start;
}

.photo-panel, .result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.canvas-toolbar {
  height: 58px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.canvas-toolbar > div:first-child { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.canvas-toolbar strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canvas-toolbar #photo-meta { color: var(--muted); font-size: 12px; }

.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  background: var(--soft);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.status-badge span { width: 7px; height: 7px; border-radius: 50%; background: #9aa0a7; }
.status-badge.ready { color: #248a4b; background: #edf9f1; }
.status-badge.ready span { background: #2ba557; }
.status-badge.review { color: #9a5a00; background: #fff7e7; }
.status-badge.review span { background: #e18a0b; }

.canvas-stage {
  width: 100%;
  min-height: 440px;
  max-height: calc(100vh - 230px);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  background: #25292e;
  touch-action: none;
}

#result-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 230px);
  width: auto;
  height: auto;
}

.canvas-placeholder { color: #e9ecef; padding: 24px; text-align: center; font-size: 16px; font-weight: 650; }
.canvas-placeholder[hidden] { display: none; }

.draw-tip {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 9px 13px;
  color: #fff;
  background: rgba(18, 20, 23, .86);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 9px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
}
.draw-tip.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.canvas-stage.drawing { cursor: crosshair; }
.workflow-hint { margin: 0; padding: 9px 16px 0; color: var(--muted); font-size: 12px; }

.canvas-foot {
  min-height: 58px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.canvas-tools { display: flex; align-items: center; gap: 16px; margin-right: auto; }

.text-button {
  border: 0;
  padding: 8px 0;
  color: var(--red);
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}
.text-button.subtle { color: var(--muted); font-weight: 650; }
.text-button.subtle:hover { color: var(--ink); }
.text-button svg { width: 18px; height: 18px; stroke-width: 2.2; }
.row-label { color: var(--muted); font-size: 13px; }
#row-title-input { width: 112px; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; outline: none; }
#row-title-input:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

.result-panel {
  position: sticky;
  top: 100px;
  min-height: 540px;
}

.result-heading {
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.result-heading h2 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.result-heading h2::before { content: ""; display: inline-block; width: 5px; height: 22px; border-radius: 4px; background: var(--red); margin-right: 9px; vertical-align: -4px; }
.result-heading p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.compact { min-width: auto !important; padding: 9px 12px !important; font-size: 13px; }

.result-list { padding: 0 18px; }
.result-row {
  min-height: 118px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 132px 30px;
  grid-template-rows: auto 32px;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.row-index, .row-fields, .stepper, .delete-button { grid-row: 1; }
.row-index { width: 28px; height: 28px; display: grid; place-items: center; color: var(--red); background: var(--red-soft); border-radius: 8px; font-weight: 800; }
.row-fields { display: grid; grid-template-columns: minmax(80px, 1fr) 70px; gap: 8px; }
.row-fields label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.row-fields input, .row-fields select { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 0 8px; color: var(--ink); font-size: 13px; outline: none; }
.row-fields input:focus, .row-fields select:focus, .count-input:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

.stepper { display: grid; grid-template-columns: 36px 58px 36px; height: 38px; border: 1px solid #cfd4d9; border-radius: 9px; overflow: hidden; }
.stepper button { border: 0; background: #fff; color: var(--ink); font-size: 22px; line-height: 1; }
.stepper button:active { background: var(--red-soft); color: var(--red); }
.count-input { width: 100%; border: 0; border-inline: 1px solid #cfd4d9; color: var(--red); text-align: center; font-size: 16px; font-weight: 800; outline: none; -moz-appearance: textfield; }
.count-input::-webkit-outer-spin-button, .count-input::-webkit-inner-spin-button { appearance: none; margin: 0; }

.delete-button { border: 0; background: transparent; color: #9ca2a9; padding: 4px; }
.delete-button:hover { color: var(--red); }
.delete-button svg { width: 19px; height: 19px; }

.closeup-tools { grid-column: 2 / 4; grid-row: 2; display: flex; align-items: center; gap: 8px; min-width: 0; }
.closeup-button { height: 30px; padding: 0 10px; border: 1px solid #f0b4b7; border-radius: 8px; color: var(--red); background: #fff; display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 750; }
.closeup-button:hover { background: var(--red-soft); }
.closeup-button svg { width: 15px; height: 15px; }
.closeup-state { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.closeup-state.done { color: #248a4b; font-weight: 700; }
.closeup-preview { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.closeup-preview:hover { color: var(--red); }
.closeup-thumb { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; border: 1px solid var(--line); }

.closeup-dialog { width: min(96vw, 800px); max-height: 92vh; padding: 0; border: 0; border-radius: 14px; box-shadow: 0 24px 80px rgba(0, 0, 0, .35); background: #fff; }
.closeup-dialog::backdrop { background: rgba(15, 18, 22, .75); }
.closeup-dialog-head { height: 48px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; }
.closeup-dialog-head strong { font-size: 14px; }
.closeup-dialog-head button { width: 34px; height: 34px; border: 0; background: #f0f1f2; border-radius: 8px; font-size: 26px; line-height: 1; }
#closeup-full { display: block; max-width: 100%; max-height: calc(92vh - 48px); margin: auto; object-fit: contain; }

.summary-panel { margin: 0 18px 16px; padding: 12px 13px; border: 1px solid #f2c3c6; border-radius: 11px; background: var(--red-soft); }
.summary-panel.hidden { display: none; }
.summary-panel > span { color: var(--red-dark); font-size: 11px; font-weight: 800; }
#summary-list { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--ink); font-size: 13px; font-weight: 750; }

.empty-state { min-height: 330px; padding: 40px; display: grid; place-items: center; align-content: center; text-align: center; color: var(--muted); }
.empty-state.hidden { display: none; }
.empty-state strong { color: var(--ink); margin: 14px 0 7px; }
.empty-state span { font-size: 13px; line-height: 1.7; }
.empty-icon { width: 64px; height: 64px; display: grid; place-items: center; color: var(--red); background: var(--red-soft); border-radius: 20px; }
.empty-icon svg { width: 31px; height: 31px; }

.action-bar { padding: 16px 18px; display: grid; grid-template-columns: .8fr 1.2fr; gap: 10px; border-top: 1px solid var(--line); background: #fff; }
.primary-button, .secondary-button {
  min-height: 48px;
  border-radius: 11px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
}
.secondary-button { color: var(--ink); background: #fff; }
.secondary-button:hover { background: var(--soft); }
.primary-button { color: #fff; background: var(--red); border-color: var(--red); box-shadow: 0 8px 18px rgba(237, 23, 31, .2); }
.primary-button:hover { background: var(--red-dark); }
.primary-button:disabled { cursor: not-allowed; color: #9da2a8; background: #eceeef; border-color: #eceeef; box-shadow: none; }
.primary-button svg, .secondary-button svg { width: 20px; height: 20px; }

.shooting-guide { width: min(1440px, calc(100% - 48px)); margin: 0 auto 34px; padding: 18px 22px; background: #fff; border: 1px solid var(--line); border-radius: 15px; }
.shooting-guide h2 { margin: 0 0 14px; font-size: 15px; }
.guide-items { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.guide-items > div { display: flex; align-items: center; gap: 11px; }
.guide-items span { flex: 0 0 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--red-soft); color: var(--red); font-weight: 800; }
.guide-items p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.guide-items strong { display: block; color: var(--ink); font-size: 13px; }

.visually-hidden { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 50; transform: translate(-50%, 16px); padding: 11px 16px; border-radius: 10px; color: #fff; background: rgba(20, 22, 25, .94); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 920px) {
  .topbar { height: 68px; padding-inline: 16px; }
  .brand p { display: none; }
  .brand h1 { font-size: 21px; }
  .brand-mark { height: 30px; width: 6px; }
  .icon-action { grid-template-columns: 21px; min-width: 42px; padding: 9px; place-items: center; }
  .icon-action span { display: none; }
  .workspace { display: block; padding: 12px 0 0; }
  .photo-panel, .result-panel { border-inline: 0; border-radius: 0; box-shadow: none; }
  .photo-panel { border-top: 0; }
  .canvas-toolbar { height: 52px; padding-inline: 13px; }
  .canvas-stage { min-height: 300px; max-height: none; }
  #result-canvas { max-height: none; width: 100%; height: auto; }
  .workflow-hint { padding-inline: 13px; }
  .canvas-foot { padding-inline: 13px; }
  .result-panel { position: static; min-height: 0; margin-top: 10px; }
  .result-heading { padding: 16px 14px; }
  .result-heading h2 { font-size: 18px; }
  .result-heading p { display: none; }
  .result-list { padding-inline: 14px; }
  .result-row { grid-template-columns: 28px minmax(0, 1fr) 126px 25px; gap: 7px; }
  .row-fields { grid-template-columns: minmax(70px, 1fr) 62px; gap: 5px; }
  .stepper { grid-template-columns: 34px 54px 34px; }
  .action-bar { position: sticky; bottom: 0; z-index: 10; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px rgba(24, 28, 34, .08); }
  .shooting-guide { width: 100%; margin: 10px 0 0; border-radius: 0; border-inline: 0; }
  .guide-items { grid-template-columns: 1fr; gap: 12px; }
}

@media (max-width: 480px) {
  .canvas-toolbar #photo-meta { display: none; }
  .status-badge { padding: 6px 8px; font-size: 11px; }
  .canvas-foot { flex-wrap: wrap; }
  .canvas-tools { width: 100%; gap: 18px; }
  .row-label { display: none; }
  #row-title-input { width: 92px; }
  .result-row { min-height: 148px; grid-template-columns: 28px minmax(0, 1fr) 25px; grid-template-rows: 48px 42px 34px; }
  .row-fields { grid-column: 2; grid-row: 1; }
  .stepper { grid-column: 2; grid-row: 2; width: 170px; grid-template-columns: 44px 80px 44px; }
  .closeup-tools { grid-column: 2; grid-row: 3; }
  .delete-button { grid-column: 3; grid-row: 1 / span 3; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
