/* CHALKAK — magazine / minimal, light, cool neutrals, small radius */
:root {
  --bg: #F4F5F6;
  --paper: #FFFFFF;
  --ink: #111214;
  --sub: #5D6168;
  --faint: #9A9FA6;
  --line: #DDE0E4;
  --line-strong: #C4C8CE;
  --accent: #1F4FE0;
  --r: 3px;
  --bar-h: 52px;
  --font: Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; overscroll-behavior: none; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .35; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  padding: var(--st) var(--sr) var(--sb) var(--sl);
}
.screen.active { display: flex; }

/* ---------- top bar ---------- */
.bar {
  flex: none;
  height: var(--bar-h);
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.bar-title {
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.bar-title small { font-weight: 500; color: var(--faint); font-size: 12px; margin-left: 4px; }
.icon-btn {
  width: 52px; height: var(--bar-h);
  display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.text-btn { height: var(--bar-h); padding: 0 16px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.bar .text-btn { justify-self: end; }

/* ---------- home ---------- */
.home { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.home-inner {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 20px 20px 32px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.mast-top {
  display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--sub);
}
.mast-top .logo { font-weight: 800; font-size: 15px; letter-spacing: .14em; color: var(--ink); }
.masthead h1 {
  margin: 28px 0 12px;
  font-size: clamp(34px, 9vw, 52px);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -0.035em;
}
.lede { margin: 0 0 28px; color: var(--sub); font-size: 15px; max-width: 30em; }

.menu-label {
  display: flex; gap: 10px; align-items: baseline;
  margin: 18px 0 0;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--ink);
  font-size: 13px; font-weight: 700;
}
.menu-label span { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.menu-row {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.menu-row .num { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; font-weight: 600; }
.menu-row .mt { display: flex; flex-direction: column; min-width: 0; }
.menu-row b { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.menu-row small { font-size: 13px; color: var(--sub); }
.menu-row:active { background: rgba(17,18,20,.04); }

.glyph { display: grid; gap: 2px; padding: 3px; background: var(--ink); border-radius: 1px; }
.glyph i { display: block; background: var(--bg); }
.glyph-strip { width: 20px; grid-template-rows: repeat(4, 8px); padding-bottom: 6px; }
.glyph-pola { width: 28px; padding: 3px 3px 9px; background: var(--paper); border: 1px solid var(--ink); }
.glyph-pola i { height: 20px; background: var(--ink); }

.home-foot { margin-top: auto; padding-top: 36px; font-size: 12px; color: var(--faint); }
.home-foot p { margin: 0 0 4px; }

/* ---------- camera ---------- */
.vf-wrap { flex: 1; min-height: 0; display: grid; place-items: center; }
.viewfinder {
  position: relative;
  overflow: hidden;
  background: #1A1B1E;
  border-radius: 2px;
}
.viewfinder video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.viewfinder video.mirror { transform: scaleX(-1); }
.viewfinder video.bw { filter: grayscale(1); }
.countdown {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #fff;
  font-size: clamp(72px, 24vw, 160px);
  font-weight: 800;
  letter-spacing: -0.04em;
  text-shadow: 0 2px 24px rgba(0,0,0,.35);
  pointer-events: none;
}
.countdown.pop { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(1.25); opacity: 0; } 15% { opacity: 1; } 100% { transform: scale(.92); opacity: .9; } }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }
.cam-msg {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 14px; padding: 20px;
  background: var(--paper);
  text-align: center; color: var(--sub);
}
.cam-msg p { margin: 0; max-width: 22em; }

.shots { flex: none; display: flex; justify-content: center; gap: 8px; padding: 4px 16px 0; }
.shot {
  width: 64px; aspect-ratio: 4 / 3;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  display: grid; place-items: center;
  font-size: 12px; color: var(--faint); font-weight: 600;
  overflow: hidden;
  background: var(--paper);
}
.shot.next { border-color: var(--ink); color: var(--ink); }
.shot canvas { width: 100%; height: 100%; display: block; }

.cam-controls {
  flex: none;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  padding: 16px 16px 18px;
}
.shutter {
  width: 74px; height: 74px;
  border: 2px solid var(--ink);
  border-radius: var(--r);
  display: grid; place-items: center;
  background: var(--paper);
}
.shutter span { width: 54px; height: 54px; background: var(--ink); border-radius: 2px; transition: transform .15s, background .15s; }
.shutter:active span { transform: scale(.9); }
.shutter.running span { width: 26px; height: 26px; background: var(--accent); }
.cam-hint { margin: 0; font-size: 13px; color: var(--sub); min-height: 1.5em; text-align: center; }

/* ---------- segmented ---------- */
.seg { display: inline-flex; border: 1px solid var(--ink); border-radius: var(--r); overflow: hidden; }
.seg button { padding: 7px 14px; font-size: 13px; font-weight: 600; border-left: 1px solid var(--ink); }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--ink); color: var(--paper); }
.seg.small button { padding: 5px 12px; font-size: 12px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: var(--r);
  background: var(--paper);
  font-size: 14px; font-weight: 600;
  text-decoration: none; color: var(--ink);
  white-space: nowrap;
}
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.ghost { border-color: var(--line-strong); color: var(--sub); }
.btn.big { min-height: 52px; font-size: 15px; justify-content: space-between; padding: 0 16px; }
.btn small { font-weight: 500; opacity: .6; font-size: 12px; font-variant-numeric: tabular-nums; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 0; }
.btn-col { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.mini { padding: 0 10px; font-size: 12px; font-weight: 600; border-left: 1px solid var(--line); color: var(--sub); }

/* ---------- editor & story layout ---------- */
.work { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; overflow: hidden; }
.canvas-box { position: relative; }
.canvas-box canvas {
  display: block; width: 100%; height: 100%;
  box-shadow: 0 1px 2px rgba(17,18,20,.08), 0 8px 28px rgba(17,18,20,.10);
  touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.sel {
  position: absolute;
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  pointer-events: none;
}
.sel.dashed { outline: 0; border: 1.5px dashed var(--accent); transform-origin: center; }
.hints { position: absolute; inset: 0; pointer-events: none; }
.cell-add {
  position: absolute;
  pointer-events: auto;
  display: grid; place-items: center;
  color: var(--sub); font-size: 13px; font-weight: 600;
}
.cell-add span { border: 1px solid var(--line-strong); background: rgba(255,255,255,.85); padding: 6px 10px; border-radius: var(--r); }

.panel {
  flex: none;
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.tabs button {
  height: 44px;
  font-size: 14px; font-weight: 600; color: var(--faint);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--ink); }
.tab-bodies { height: 214px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.tab-body { display: none; padding: 12px 16px 16px; flex-direction: column; gap: 12px; }
.tab-body.on { display: flex; }

.k { font-size: 13px; font-weight: 600; color: var(--sub); }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 28px; }
.kv .v { font-size: 14px; font-weight: 700; }
.hint { margin: 0; font-size: 12px; color: var(--faint); }

.range { display: grid; grid-template-columns: 52px 1fr 44px; align-items: center; gap: 10px; }
.range output { text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 30px; margin: 0;
  background: transparent;
  --p: 50%;
  touch-action: pan-y;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(to right, var(--ink) 0 var(--p), var(--line) var(--p) 100%);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px; margin-top: -9px;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
}
input[type=range]::-moz-range-track { height: 2px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 2px; background: var(--ink); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; background: var(--paper); border: 1.5px solid var(--ink); border-radius: 2px; }
input[type=range]:disabled { opacity: .35; }

.switch-row { display: flex; justify-content: space-between; align-items: center; min-height: 36px; }
.switch {
  -webkit-appearance: none; appearance: none;
  width: 46px; height: 26px; margin: 0;
  border: 1.5px solid var(--ink);
  border-radius: var(--r);
  position: relative;
  background: var(--paper);
  cursor: pointer;
}
.switch::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 17px; height: 17px; border-radius: 2px;
  background: var(--ink);
  transition: transform .15s;
}
.switch:checked { background: var(--ink); }
.switch:checked::before { background: var(--paper); transform: translateX(20px); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 34px; height: 34px;
  border-radius: 2px;
  border: 1px solid var(--line-strong);
  position: relative;
}
.swatch.on { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch.custom {
  overflow: hidden;
  background: conic-gradient(from 0deg, #E3E6EA, #9FB3D1, #2C3E66, #6E7A8A, #C9D6CF, #E3E6EA);
  display: grid; place-items: center;
}
.swatch.custom input { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); opacity: 0; cursor: pointer; border: 0; padding: 0; }
.swatch.custom::after { content: "+"; color: #fff; font-weight: 700; text-shadow: 0 0 4px rgba(0,0,0,.4); pointer-events: none; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-in { display: flex; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--paper); }
.field-in input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 12px; font-size: 16px; outline: none; }
.txt-edit { display: flex; flex-direction: column; gap: 10px; }
.txt-edit textarea {
  width: 100%; resize: none;
  border: 1px solid var(--line-strong); border-radius: var(--r);
  padding: 10px 12px; font-size: 16px; line-height: 1.4;
  background: var(--paper); outline: none;
}
.field-in:focus-within, .txt-edit textarea:focus { border-color: var(--ink); }

/* ---------- sheet & toast ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(17,18,20,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  width: 100%; max-width: 480px;
  background: var(--paper);
  border-radius: var(--r) var(--r) 0 0;
  padding: 6px 16px calc(16px + var(--sb));
  display: flex; flex-direction: column; gap: 10px;
  max-height: 90vh;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head .text-btn { height: 44px; padding: 0 4px; color: var(--sub); }
.sheet-img { min-height: 0; display: grid; place-items: center; background: var(--bg); padding: 12px; }
.sheet-img img { max-width: 100%; max-height: 52vh; display: block; -webkit-touch-callout: default; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--sb)); z-index: 30;
  transform: translate(-50%, 12px);
  background: var(--ink); color: var(--paper);
  padding: 10px 14px; border-radius: var(--r);
  font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- wide screens: panel on the side ---------- */
@media (min-width: 900px) and (min-height: 560px) {
  .work { flex-direction: row; }
  .panel { width: 360px; border-top: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
  .tab-bodies { height: auto; flex: 1; }
  .camera .vf-wrap { padding-top: 8px; }
}

@media (max-height: 640px) {
  .tab-bodies { height: 176px; }
  .cam-controls { gap: 10px; padding: 10px 16px 12px; }
  .shutter { width: 64px; height: 64px; }
  .shutter span { width: 46px; height: 46px; }
}

/* hover effects only for real mouse pointers (never on touch) */
@media (hover: hover) and (pointer: fine) {
  .menu-row { transition: background .15s; }
  .menu-row:hover { background: rgba(17,18,20,.035); }
  .menu-row:hover b { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }
  .btn:hover { background: var(--bg); }
  .btn.primary:hover { background: #2A2C30; }
  .tabs button:hover { color: var(--ink); }
  .seg button:not(.on):hover { background: var(--bg); }
  .icon-btn:hover svg { stroke: var(--accent); }
  .text-btn:hover { color: var(--accent); }
  .swatch:hover { transform: translateY(-1px); }
}
