:root {
  --ink: #111111;
  --on-primary: #ffffff;
  --ink-muted: #626260;
  --ink-subtle: #7b7b78;
  --ink-tertiary: #9c9fa5;
  --canvas: #f5f1ec;
  --surface-1: #ffffff;
  --surface-2: #ebe7e1;
  --hairline: #d3cec6;
  --hairline-soft: #ebe7e1;
  --study: #1f5c45;
  --study-soft: #e4efe8;
  --receipt-paper: #fffdf8;
  --receipt-ink: #1a1a1a;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font: "Pretendard", "Inter", ui-sans-serif, system-ui, sans-serif;
  --receipt-font: "IBM Plex Sans KR", "Pretendard", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.top-nav {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 40px;
  padding: 36px 28px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--canvas);
}

.brand {
  display: flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand img {
  height: 52px;
  width: auto;
}

.nav-links {
  display: flex;
  gap: 8px;
}

.nav-chip {
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
}

.nav-chip.is-active {
  background: var(--surface-1);
  color: var(--ink);
}

.nav-chip.is-soon {
  opacity: 0.55;
}

.page {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 48px 0 96px;
}

.intro {
  max-width: 640px;
  margin-bottom: 48px;
}

.eyebrow {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--study);
}

.intro h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 40px);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.8px;
}

.lede {
  margin: 16px 0 0;
  max-width: 460px;
  color: var(--ink-muted);
  font-size: 18px;
  line-height: 1.5;
  letter-spacing: -0.1px;
}

.mobile-tabs {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  grid-template-areas:
    "editor preview"
    "dock preview";
  gap: 24px;
  align-items: start;
}

.editor-card {
  grid-area: editor;
}

.preview-pane {
  grid-area: preview;
}

.app-dock {
  grid-area: dock;
}

.editor-card,
.preview-pane,
.app-dock {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  padding: 24px;
}

.card-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.3px;
}

.card-head p {
  margin: 6px 0 0;
  color: var(--ink-subtle);
  font-size: 14px;
}

.card-head {
  margin-bottom: 24px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.field span {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--ink);
  padding: 10px 14px;
  min-height: 44px;
}

.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23626260' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.field input:focus,
.field select:focus {
  outline: 2px solid var(--study);
  outline-offset: 1px;
}

.subjects {
  margin: 8px 0 20px;
}

.subjects-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
}

.subject-cols {
  display: grid;
  grid-template-columns: 1fr 88px 72px 36px;
  gap: 8px;
  padding: 0 0 6px;
  font-size: 12px;
  color: var(--ink-tertiary);
}

.subject-row {
  display: grid;
  grid-template-columns: 1fr 88px 72px 36px;
  gap: 8px;
  margin-bottom: 8px;
}

.subject-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--surface-1);
}

.subject-row input:focus {
  outline: 2px solid var(--study);
  outline-offset: 1px;
}

.icon-btn,
.text-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.text-btn {
  padding: 8px 0;
  font-size: 14px;
  font-weight: 500;
}

.icon-btn {
  min-height: 44px;
  color: var(--ink-subtle);
}

.icon-btn:hover,
.text-btn:hover {
  color: var(--study);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.actions .btn-tertiary {
  grid-column: 1 / -1;
}

.save-menu {
  position: relative;
}

.save-menu .btn-primary {
  width: 100%;
}

.save-menu-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  padding: 4px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}

.save-menu-list button {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.save-menu-list button:hover {
  background: var(--canvas);
}

.btn-primary,
.btn-secondary,
.btn-tertiary {
  min-height: 40px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary {
  background: var(--ink);
  color: var(--on-primary);
}

.btn-primary:hover {
  background: #000;
}

.btn-secondary {
  background: var(--surface-1);
  color: var(--ink);
  border-color: var(--hairline);
}

.btn-tertiary {
  background: var(--canvas);
  color: var(--ink);
}

.hint {
  min-height: 1.4em;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--ink-subtle);
}

.preview-pane {
  position: sticky;
  top: 104px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.design-picker {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--ink-muted);
}

.preview-pane:has(.stage[data-view="story"]) .design-picker {
  display: flex;
}

.design-picker button {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.design-picker button.is-selected {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-primary);
}

.preview-meta {
  margin: 0;
  font-size: 12px;
  color: var(--ink-tertiary);
}

.view-toggle {
  display: flex;
  padding: 4px;
  background: var(--canvas);
  border-radius: 9999px;
}

.view-toggle button {
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  padding: 8px 16px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.view-toggle button.is-selected {
  background: var(--surface-1);
  color: var(--ink);
}

.stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 640px;
  max-height: 860px;
  overflow: auto;
  padding: 36px 8px 32px;
  background: var(--canvas);
  border-radius: var(--radius-lg);
}

.story-head,
.story-foot {
  display: none;
}

.stage[data-view="story"] {
  background: linear-gradient(180deg, #163d30 0%, #1f5c45 100%);
  padding: 0;
  aspect-ratio: 9 / 16;
  max-height: none;
  min-height: 0;
  max-width: 360px;
  margin: 0 auto;
  overflow: hidden;
}

.stage[data-view="story"] .story-sheet {
  width: 100%;
  height: 100%;
  padding: 32px 20px 28px;
}

.stage[data-view="story"] .story-sheet[data-layout="center"] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
}

.stage[data-view="story"] .story-sheet[data-layout="center"] .story-copy {
  display: contents;
}

.stage[data-view="story"] .story-sheet[data-layout="center"] .story-head {
  order: 1;
}

.stage[data-view="story"] .story-sheet[data-layout="center"] .receipt-slot {
  order: 2;
}

.stage[data-view="story"] .story-sheet[data-layout="center"] .story-foot {
  order: 3;
}

.stage[data-view="story"] .story-sheet[data-layout="right"] {
  display: grid;
  grid-template-columns: 1.18fr 0.92fr;
  gap: 10px;
  padding: 24px 16px;
}

.stage[data-view="story"] .story-sheet[data-layout="right"] .receipt-slot {
  order: -1;
  margin: 0;
  align-self: stretch;
}

.stage[data-view="story"] .story-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
}

.stage[data-view="story"] .story-head,
.stage[data-view="story"] .story-foot {
  display: block;
  flex-shrink: 0;
  text-align: center;
  color: #f3f7f4;
}

.stage[data-view="story"] .story-sheet[data-layout="right"] .story-head,
.stage[data-view="story"] .story-sheet[data-layout="right"] .story-foot {
  text-align: right;
}

.stage[data-view="story"] .story-kicker {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: rgba(243, 247, 244, 0.7);
}

.stage[data-view="story"] .story-brand {
  margin: 0;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.4px;
}

.stage[data-view="story"] .story-lead {
  margin: 8px 0 0;
  font-size: 13px;
  color: rgba(243, 247, 244, 0.78);
}

.stage[data-view="story"] .story-sheet[data-layout="right"] .story-copy {
  gap: 72px;
}

.stage[data-view="story"] .receipt-slot {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin: 12px 0;
}

.stage[data-view="story"] .receipt-export {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 320px;
  transform-origin: center center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.stage[data-view="story"] .story-hours {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 500;
}

.stage[data-view="story"] .story-meta,
.stage[data-view="story"] .story-url {
  margin: 0;
  font-size: 12px;
  color: rgba(243, 247, 244, 0.72);
}

.stage[data-view="story"] .story-url {
  margin-top: 10px;
}

.receipt-export {
  width: 320px;
  background: var(--receipt-paper);
  color: var(--receipt-ink);
  font-family: var(--receipt-font);
  font-size: 12px;
  line-height: 1.45;
  padding: 36px 20px 24px;
  border: 1px solid #e6e1d8;
}

.item-table {
  table-layout: fixed;
}

.item-table th:nth-child(1),
.item-table td:nth-child(1) {
  width: 42%;
}

.item-table th:nth-child(2),
.item-table td:nth-child(2),
.item-table th:nth-child(3),
.item-table td:nth-child(3),
.item-table th:nth-child(4),
.item-table td:nth-child(4) {
  width: 19%;
}

.receipt-logo {
  display: block;
  width: 168px;
  height: auto;
  margin: 8px auto 28px;
}

.receipt-no {
  margin: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.receipt-title {
  margin: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}

.dash {
  height: 0;
  margin: 10px 0;
  border-top: 1px dashed #222;
}

.store {
  margin-bottom: 10px;
}

.store p {
  margin: 0;
}

.store-name {
  font-size: 13px;
  font-weight: 600;
}

.when {
  margin: 10px 0 8px;
}

.item-table {
  width: 100%;
  border-collapse: collapse;
}

.item-table th,
.item-table td {
  padding: 3px 0;
  font-weight: 400;
  text-align: left;
  vertical-align: top;
}

.item-table th {
  font-weight: 600;
}

.item-table .num,
.item-table th.num,
.item-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.item-name {
  padding-right: 8px;
  word-break: break-word;
}

.subtotal {
  margin: 8px 0 0;
  text-align: right;
  font-weight: 600;
}

.section-label {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 600;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.grand {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 8px;
  font-size: 18px;
  font-weight: 700;
}

.grand strong {
  font-size: 22px;
}

.barcode {
  display: block;
  width: 100%;
  height: 64px;
  margin: 6px 0 4px;
}

.barcode-num {
  margin: 0;
  text-align: center;
  letter-spacing: 0.4px;
  font-variant-numeric: tabular-nums;
}

.brand-url {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 400;
}

.foot-line {
  margin: 0;
}

.site-footer {
  padding: 64px 32px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 12px;
}

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "editor"
      "preview"
      "dock";
  }

  .preview-pane {
    position: static;
  }
}

@media (max-width: 768px) {
  body {
    padding-bottom: calc(108px + env(safe-area-inset-bottom));
  }

  .top-nav {
    min-height: 56px;
    padding: 10px 16px;
    gap: 12px;
  }

  .brand img {
    height: 32px;
  }

  .nav-links {
    display: none;
  }

  .mobile-tabs {
    display: flex;
    position: sticky;
    top: 56px;
    z-index: 9;
    margin: 0 16px;
    padding: 4px;
    background: var(--surface-2);
    border-radius: 9999px;
  }

  .mobile-tabs button {
    flex: 1;
    min-height: 40px;
    border: 0;
    border-radius: 9999px;
    background: transparent;
    color: var(--ink-muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
  }

  .mobile-tabs button.is-selected {
    background: var(--surface-1);
    color: var(--ink);
  }

  .page {
    width: 100%;
    padding: 12px 16px 24px;
  }

  .intro,
  .site-footer,
  .card-head {
    display: none;
  }

  .editor-card,
  .preview-pane {
    border: 0;
    border-radius: 0;
    padding: 8px 0 16px;
    background: transparent;
  }

  body[data-mobile-panel="edit"] .preview-pane,
  body[data-mobile-panel="preview"] .editor-card {
    display: none;
  }

  .preview-toolbar {
    margin-bottom: 10px;
  }

  .preview-meta {
    display: none;
  }

  .stage {
    min-height: 0;
    max-height: none;
    padding: 16px 0 24px;
  }

  .stage[data-view="story"] {
    max-width: min(360px, 100%);
  }

  .app-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    border: 0;
    border-top: 1px solid var(--hairline);
    border-radius: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--canvas);
  }

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

  .actions .btn-tertiary {
    display: none;
  }

  .hint {
    margin: 8px 0 0;
    text-align: center;
  }

  .save-menu-list {
    top: auto;
    bottom: calc(100% + 6px);
  }

  .field-row {
    grid-template-columns: 1fr 1fr;
  }

  .subject-cols {
    display: none;
  }

  .subject-row {
    grid-template-columns: 1fr 72px 64px 36px;
  }

  .icon-btn {
    justify-self: end;
  }
}
