* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f6faf8;
  --panel: #ffffff;
  --panel-2: #eef6f2;
  --line: #c8d9d1;
  --text: #12211b;
  --muted: #65766f;
  --accent: #159b6c;
  --accent-2: #3f7ecb;
  --warn: #b7791f;
  --danger: #c84f67;
}

body {
  margin: 0;
  min-height: 100svh;
  background: linear-gradient(180deg, #eff8f4 0%, var(--bg) 44%);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans KR", Arial, sans-serif;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: min(720px, calc(100vw - 22px));
  min-height: 100svh;
  margin: 0 auto;
  padding: 8px 0 calc(10px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  padding: 2px 0 6px;
}

.brand-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(21, 155, 108, 0.45);
  border-radius: 10px;
  background: #e8f6ef;
  color: var(--accent);
  font-size: 19px;
  font-weight: 900;
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}

.sub {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.step-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 7px 0;
  background: rgba(246, 250, 248, 0.94);
  backdrop-filter: blur(8px);
}

.two-tabs {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.step-tab,
.mode-btn,
.primary,
.secondary,
.ghost,
.photo-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-weight: 900;
}

.step-tab.active,
.mode-btn.active,
.primary,
.photo-button {
  border-color: var(--accent);
  background: #dff5eb;
  color: #08714c;
}

.secondary {
  border-color: #9fc4ef;
  background: #edf5ff;
  color: #1e5eaa;
}

.ghost {
  background: #f7faf8;
  color: var(--muted);
}

.step-page {
  display: none;
}

.step-page.active {
  display: block;
}

.panel,
.work-card,
.result-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  padding: 10px;
}

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

.field {
  display: grid;
  gap: 7px;
}

label,
.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input[type="text"],
input:not([type]) {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdfc;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

.mode-grid,
.action-grid,
.save-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.photo-button {
  display: grid;
  place-items: center;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.work-card {
  display: grid;
  gap: 8px;
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  height: min(58svh, 560px);
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef4f1;
  touch-action: none;
  user-select: none;
}

canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

.camera-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #07120f;
}

.shoot-guide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}

.shoot-guide[hidden] {
  display: none;
}

.shoot-box {
  width: min(82%, 430px);
  height: min(76%, 430px);
  border: 4px solid #f4b83f;
  border-radius: 14px;
  background: rgba(244, 184, 63, 0.05);
  box-shadow: 0 0 0 999px rgba(4, 18, 15, 0.16);
}

.shoot-guide span {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(7, 18, 15, 0.76);
  color: #ffffff;
  text-align: center;
  font-size: 13px;
  font-weight: 900;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.auto-note {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid #d7e4df;
  border-radius: 8px;
  background: #fbfdfc;
}

.auto-note strong {
  color: var(--accent);
  font-size: 13px;
}

.auto-note span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.next-line {
  display: grid;
}

.inline-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.75fr);
  gap: 9px;
  align-items: stretch;
}

.inline-result div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #d7e4df;
  border-radius: 8px;
  background: #fbfdfc;
}

.inline-result span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.inline-result strong {
  color: var(--accent);
  font-size: 30px;
  line-height: 1;
}

.result-card {
  display: grid;
  gap: 12px;
}

.count-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.compact-count {
  min-height: 74px;
}

#countValue {
  display: block;
  margin-top: 2px;
  font-size: 56px;
  line-height: 1;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(2, 64px);
  gap: 8px;
}

.stepper button {
  height: 62px;
  border-radius: 10px;
  color: #07120f;
  font-size: 30px;
  font-weight: 900;
}

#minusBtn {
  background: #f2cf76;
}

#plusBtn {
  background: #64e6b8;
}

.history-panel {
  margin-top: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h2 {
  margin: 0;
  font-size: 18px;
}

.small {
  min-height: 34px;
  padding: 0 12px;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 34svh;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid #d7e4df;
  border-radius: 8px;
  background: #fbfdfc;
}

.history-title {
  font-weight: 900;
  overflow-wrap: anywhere;
}

.history-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.history-count {
  color: var(--accent);
  font-size: 24px;
  font-weight: 900;
}

@media (max-width: 480px) {
  .app-shell {
    width: min(420px, calc(100vw - 16px));
    padding-top: 6px;
  }

  h1 {
    font-size: 26px;
  }

  .sub {
    font-size: 10px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .panel,
  .work-card,
  .result-card {
    padding: 11px;
  }

  .canvas-wrap {
    height: min(58svh, 520px);
    min-height: 340px;
  }

  .stepper {
    grid-template-columns: repeat(2, 56px);
  }

  .stepper button {
    height: 58px;
  }

  .inline-result {
    grid-template-columns: 1fr;
  }
}
