:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #202322;
  --muted: #69706d;
  --line: #d9ded9;
  --accent: #19705a;
  --accent-strong: #0d5846;
  --sheet-area: #e8ece8;
  --focus: rgba(25, 112, 90, 0.2);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
  font-weight: 800;
}

h2 {
  font-size: 15px;
}

.lead,
.status,
.section-title span,
.canvas-help {
  color: var(--muted);
  font-size: 13px;
}

.lead {
  margin-top: 7px;
}

.actions {
  display: flex;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.sheet-wrap {
  position: relative;
  width: 100%;
  min-height: 440px;
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sheet-area);
  transition: border-color 0.18s, background 0.18s;
}

.sheet-wrap.drag-over {
  border-color: var(--accent);
  background: #dfeae5;
}

.sheet {
  width: min(100%, 720px);
  aspect-ratio: 210 / 297;
  height: auto;
  display: block;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(25, 30, 28, 0.16);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.sheet:active {
  cursor: grabbing;
}

.sheet:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.sheet-wrap[data-empty="true"] .sheet {
  opacity: 0.72;
  cursor: default;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(280px, calc(100% - 48px));
  display: grid;
  justify-items: center;
  gap: 7px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  font-size: 15px;
}

.empty-state span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.empty-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 3px;
  border: 1px solid #c7d1ca;
  border-radius: 50%;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.8);
  font-size: 27px;
  font-weight: 300;
}

.canvas-help {
  margin-top: 9px;
  text-align: center;
}

.panel {
  display: grid;
  gap: 12px;
}

.panel-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.button.primary {
  color: #fff;
  background: var(--accent);
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button.ghost {
  border-color: var(--line);
}

.button.ghost:hover:not(:disabled) {
  border-color: #bfc8c1;
  background: #fafbfa;
}

.button.full {
  width: 100%;
}

.button:disabled,
.tool:disabled,
input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button input {
  display: none;
}

.file-summary {
  min-width: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
}

.thumb-preview {
  width: 54px;
  height: 54px;
  border-radius: 7px;
  background: #eef2ef center / cover no-repeat;
}

.file-summary > div:last-child {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.file-summary strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-summary span {
  color: var(--muted);
  font-size: 12px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}

.tool {
  min-width: 0;
  height: 58px;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 4px 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font-size: 23px;
  line-height: 1;
  cursor: pointer;
}

.tool:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.tool span {
  font-size: 10px;
  font-weight: 700;
}

.control {
  display: grid;
  gap: 7px;
  margin: 13px 0;
  color: var(--muted);
  font-size: 13px;
}

.control > span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.control b {
  color: var(--muted);
  font-weight: 700;
}

.control output {
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

.range-number-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  align-items: center;
  gap: 10px;
}

.unit-input {
  min-height: 38px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding-right: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.unit-input input {
  min-width: 0;
  width: 100%;
  height: 36px;
  padding: 0 0 0 8px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.unit-input > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.unit-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--focus);
}

.segment-field {
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.segment-field legend,
.select-control > span {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segments {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f6f4;
}

.segments label {
  cursor: pointer;
}

.segments input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segments span {
  min-height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}

.segments input:checked + span {
  color: var(--accent);
  background: #fff;
  box-shadow: 0 1px 4px rgba(25, 30, 28, 0.1);
}

.segments input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.select-control {
  display: grid;
  margin-bottom: 14px;
}

.select-control select {
  width: 100%;
  min-height: 40px;
  padding: 0 36px 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
}

.save-button {
  min-height: 46px;
}

.status {
  margin-top: 12px;
  line-height: 1.5;
}

.privacy-note {
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid #edf0ed;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.crop-dialog {
  width: min(1000px, calc(100vw - 28px));
  max-width: none;
  max-height: calc(100vh - 28px);
  padding: 0;
  border: 0;
  border-radius: 10px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

.crop-dialog::backdrop {
  background: rgba(20, 24, 22, 0.72);
}

.crop-dialog-inner {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.crop-dialog-header,
.crop-dialog-actions,
.crop-dialog-actions > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.crop-dialog-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.dialog-close {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
  font-size: 28px;
  cursor: pointer;
}

.crop-stage {
  min-height: 240px;
  max-height: calc(100vh - 190px);
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: #252927;
}

.crop-stage canvas {
  max-width: 100%;
  max-height: calc(100vh - 220px);
  width: auto;
  height: auto;
  display: block;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.site-footer {
  border-top: 1px solid var(--line);
  background: #fff;
}

.footer-inner {
  width: min(1180px, calc(100vw - 32px));
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.footer-inner nav {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.footer-inner a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.footer-inner a:hover {
  text-decoration: underline;
}

.terms-page {
  width: min(860px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.terms-header {
  margin-bottom: 22px;
}

.terms-header a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.terms-header h1 {
  margin-top: 16px;
}

.terms-header p {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.7;
}

.terms-content {
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.terms-content h2 {
  margin: 28px 0 8px;
  font-size: 17px;
}

.terms-content h2:first-child {
  margin-top: 0;
}

.terms-content p,
.terms-content li {
  color: #4a5568;
  font-size: 14px;
  line-height: 1.85;
}

.terms-content ul {
  padding-left: 1.3em;
}

.terms-date {
  margin-top: 28px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 860px) {
  .app {
    width: min(100vw - 20px, 680px);
    padding-top: 12px;
  }

  .topbar,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 25px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sheet-wrap {
    min-height: 360px;
    padding: 8px;
  }

  .panel {
    gap: 10px;
  }

  .footer-inner {
    width: min(100vw - 20px, 680px);
    min-height: auto;
    padding: 18px 0;
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .sheet-wrap {
    min-height: 300px;
  }

  .canvas-help {
    font-size: 11px;
  }

  .crop-dialog-inner {
    padding: 14px;
  }

  .crop-dialog-header p {
    max-width: 260px;
  }

  .crop-dialog-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .crop-dialog-actions > .button,
  .crop-dialog-actions > div,
  .crop-dialog-actions > div .button {
    width: 100%;
  }
}

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