: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;
  --study: #1f5c45;
  --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;
}
button, input, select { font: inherit; }

.top-nav {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--canvas);
}
.brand { display: flex; align-items: center; }
.brand img { height: 44px; width: auto; }

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

.screen { display: none; }
body[data-screen="home"] #screen-home,
body[data-screen="create"] #screen-create,
body[data-screen="session"] #screen-session,
body[data-screen="receipt"] #screen-receipt { display: block; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  padding: 24px;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 20px;
  align-items: start;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--study);
}
h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: -0.3px; }
h1 { font-size: 22px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.cal-week,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}
.cal-week {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-tertiary);
}
.cal-cell {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  cursor: pointer;
  position: relative;
}
.cal-cell.is-empty { cursor: default; }
.cal-cell.is-today { background: var(--surface-2); }
.cal-cell.is-selected { background: var(--ink); color: var(--on-primary); }
.cal-cell.has-group i {
  display: block;
  width: 5px;
  height: 5px;
  margin: 4px auto 0;
  border-radius: 50%;
  background: var(--study);
}
.cal-cell.is-selected.has-group i { background: #fff; }

.day-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.group-list { display: grid; gap: 10px; }
.group-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
}
.group-status {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--study);
}
.group-card p { margin: 4px 0 0; font-size: 13px; color: var(--ink-muted); }
.empty { margin: 24px 0; color: var(--ink-subtle); }

.card-head { margin-bottom: 20px; }
.card-head p { margin: 8px 0 0; color: var(--ink-subtle); font-size: 14px; }
.form-panel { max-width: 640px; }

.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);
  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;
}
.subjects { margin: 8px 0 20px; }
.subjects-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
}
.subject-cols,
.subject-row {
  display: grid;
  grid-template-columns: 56px 1fr 110px 40px;
  gap: 8px;
  align-items: center;
}
.subject-cols { font-size: 12px; color: var(--ink-tertiary); margin-bottom: 6px; }
.subject-row {
  margin-bottom: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition: opacity 0.15s ease, background-color 0.15s ease;
}
.subject-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.subject-drag-handle:active {
  cursor: grabbing;
}
.drag-icon {
  font-size: 13px;
  letter-spacing: -2px;
  color: var(--ink-tertiary);
  line-height: 1;
}
.subject-row.is-dragging {
  opacity: 0.4;
  background: var(--surface-2);
  border-color: var(--study);
}
.subject-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.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-secondary {
  background: var(--surface-1);
  color: var(--ink);
  border-color: var(--hairline);
}
.btn-tertiary { background: var(--canvas); color: var(--ink); }
.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: 40px; min-width: 40px; font-size: 22px; color: var(--ink-subtle); }

.session-panel { max-width: 520px; margin: 24px auto; text-align: center; padding: 40px 28px; }
.session-place { margin: 8px 0 0; color: var(--ink-muted); }
.now-label {
  margin: 28px 0 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--ink-subtle);
}
.now-subject {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  color: var(--study);
}
.now-meta {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--ink-muted);
}
.timer {
  margin: 24px 0 8px;
  font-size: 56px;
  font-weight: 500;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}
.timer-caption { margin: 0 0 24px; color: var(--ink-subtle); }
.session-subjects {
  list-style: none;
  margin: 0 0 28px;
  padding: 0;
  color: var(--ink-muted);
}
.session-subjects li { margin: 4px 0; }
.session-subjects li.is-current {
  color: var(--ink);
  font-weight: 600;
}
.session-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}
.session-controls .btn-secondary,
.session-controls .btn-tertiary {
  flex: 1;
  max-width: 200px;
}
.session-controls .btn-tertiary {
  border-color: var(--hairline);
}
.session-panel.is-paused .timer,
.session-panel.is-paused .now-subject {
  opacity: 0.45;
}
.session-panel .btn-primary { width: 100%; }

.receipt-layout { max-width: 420px; margin: 0 auto; }
.preview-pane { padding: 20px; }
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.design-picker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--ink-muted);
}
.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);
}
.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;
  min-height: 560px;
  padding: 16px 8px 24px;
  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-width: 360px;
  margin: 0 auto;
  overflow: hidden;
}
.stage[data-view="story"] .story-sheet {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1.18fr 0.92fr;
  gap: 10px;
  padding: 24px 16px;
}
.stage[data-view="story"] .story-sheet .receipt-slot {
  order: -1;
  margin: 0;
  align-self: stretch;
}
.stage[data-view="story"] .story-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 72px;
}
.stage[data-view="story"] .story-head,
.stage[data-view="story"] .story-foot {
  display: block;
  color: #f3f7f4;
  text-align: center;
}
.stage[data-view="story"] .story-head,
.stage[data-view="story"] .story-foot { text-align: right; }
.stage[data-view="story"] .story-kicker {
  margin: 0 0 6px;
  font-size: 11px;
  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;
}
.stage[data-view="story"] .story-lead {
  margin: 8px 0 0;
  font-size: 13px;
  color: rgba(243, 247, 244, 0.78);
}
.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;
}
.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; }
.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; 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%; }
.item-table th, .item-table td { padding: 3px 0; text-align: left; }
.item-table th { font-weight: 600; }
.item-table .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; 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; font-variant-numeric: tabular-nums; }
.brand-url { margin: 0 0 8px; text-align: center; }
.foot-line { margin: 0; }

.app-dock {
  position: sticky;
  bottom: 0;
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 12px 0 24px;
  background: var(--canvas);
}
.app-dock[hidden] { display: none; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.save-menu { position: relative; }
.save-menu .btn-primary { width: 100%; }
.save-menu-list {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 8;
  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;
  text-align: left;
  cursor: pointer;
}
.save-menu-list button:hover { background: var(--canvas); }
.hint { min-height: 1.4em; margin: 10px 0 0; font-size: 13px; color: var(--ink-subtle); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(17, 17, 17, 0.35);
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(420px, 100%);
  background: var(--surface-1);
  border-radius: var(--radius-xl);
  padding: 24px;
}

@media (max-width: 860px) {
  .home-grid { grid-template-columns: 1fr; }
  .top-nav { min-height: 56px; padding: 10px 16px; }
  .brand img { height: 32px; }
  .page { width: calc(100% - 24px); }
  .field-row { grid-template-columns: 1fr 1fr; }
  .subject-cols { display: none; }
  .subject-row { grid-template-columns: 48px 1fr 80px 36px; }
  .timer { font-size: 44px; }
  .stage[data-view="story"] { max-width: min(360px, 100%); }
  .app-dock {
    position: sticky;
    width: calc(100% - 24px);
  }
}
