/* 손글씨 놀이터 · DESIGN.md의 색과 크기 규칙을 따른다. */
:root {
  --bg: #FFFFFF;
  --ink: #292547;
  --muted: #5F5B7A;
  --line: #E4E2EE;
  --banner: #514FA3;
  --primary: #12624D;
  --tab-bg: #D8EBDD;
  --butter: #F7DA7A;
  --rose: #EBA7AA;
  --leaf: #B9E8CC;
  --sky: #CFE7FC;
  --warn: #A8323A;
  --warn-bg: #FBEDEE;
  --radius: 22px;
  --font: 'NanumSquareRound', 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/25px var(--font);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10; background: #fff;
  display: flex; align-items: center; gap: 24px;
  padding: 8px max(20px, env(safe-area-inset-left)) 8px max(20px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 20px; color: var(--ink); text-decoration: none; padding: 12px 0; }
.tabs { display: flex; gap: 8px; }
.tabs a {
  min-height: 48px; display: inline-flex; align-items: center; padding: 0 20px;
  border-radius: 24px; font-weight: 700; color: var(--ink); text-decoration: none;
}
.tabs a[aria-current="page"] { background: var(--tab-bg); color: var(--primary); }

main { max-width: 1180px; margin: 0 auto; padding: 20px 20px 120px; outline: none; }

.btn {
  min-height: 48px; min-width: 48px; padding: 0 22px; border-radius: 24px; border: 2px solid var(--line);
  background: #fff; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; text-decoration: none; color: var(--ink);
}
.btn:focus-visible, .tabs a:focus-visible, .card:focus-visible, .tile:focus-visible { outline: 3px solid var(--banner); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-big { min-height: 64px; padding: 0 34px; font-size: 21px; border-radius: 32px; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn-on-banner { border-color: rgba(255, 255, 255, .85); }
.btn-ghost-banner { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .6); }

/* 홈 */
.banner {
  background: var(--banner); color: #fff; border-radius: 28px; padding: 32px 36px;
  display: grid; grid-template-columns: 1.15fr 1fr; gap: 24px; align-items: center;
}
.banner h1 { font-size: 36px; line-height: 48px; font-weight: 800; }
.banner p { margin-top: 10px; font-size: 18px; line-height: 28px; opacity: .95; max-width: 30em; }
.banner .actions { margin-top: 24px; display: flex; flex-wrap: wrap; gap: 12px; }
.banner img { width: 100%; height: auto; display: block; }
.section-title { font-size: 24px; line-height: 34px; font-weight: 800; margin: 36px 0 6px; }
.section-note { color: var(--muted); margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.card {
  border-radius: var(--radius); border: 2px solid var(--line); background: #fff; padding: 0; text-align: left;
  cursor: pointer; overflow: hidden; display: flex; flex-direction: column;
}
.card .art { aspect-ratio: 3 / 2; position: relative; }
.card .art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .chip { position: absolute; top: 12px; right: 12px; }
.card .text { padding: 14px 18px 18px; }
.card h3 { font-size: 21px; line-height: 30px; font-weight: 700; }
.card p { color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px; border-radius: 14px;
  font-size: 14px; font-weight: 700; background: #fff; color: var(--ink); border: 1px solid var(--line);
}
.chip-ok { background: var(--tab-bg); color: var(--primary); border-color: transparent; }
.chip-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip-off { background: #F1F0F6; color: var(--muted); border-color: transparent; }

/* 단계 표시 */
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 20px; flex-wrap: wrap; }
.steps li { padding: 8px 16px; border-radius: 20px; background: #F1F0F6; color: var(--muted); font-weight: 700; }
.steps li[aria-current="step"] { background: var(--tab-bg); color: var(--primary); }
.page-title { font-size: 28px; line-height: 38px; font-weight: 800; }
.page-lead { color: var(--muted); margin: 6px 0 20px; font-size: 18px; line-height: 28px; }

/* 쓰기 가이드 */
.sets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.set {
  min-height: 96px; text-align: left; border: 2px solid var(--line); border-radius: 20px; background: #fff; padding: 14px 16px;
  cursor: pointer; display: flex; flex-direction: column; gap: 2px;
}
.set b { font-size: 21px; line-height: 30px; }
.set span { color: var(--muted); }
.set small { font-size: 14px; color: var(--muted); font-weight: 700; }
.set[aria-pressed="true"] { border-color: var(--primary); background: var(--tab-bg); }
.set[aria-pressed="true"] b, .set[aria-pressed="true"] small { color: var(--primary); }
.set:focus-visible, .slot:focus-visible, .sheet-thumb:focus-visible { outline: 3px solid var(--banner); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; margin-bottom: 12px; font-weight: 700; }
.check input { width: 24px; height: 24px; accent-color: var(--primary); }
.sheet-row { display: flex; gap: 16px; overflow-x: auto; padding: 12px 2px 6px; }
.sheet-thumb { flex: 0 0 auto; width: 220px; border: 2px solid var(--line); border-radius: 14px; background: #fff; padding: 6px; cursor: zoom-in; text-align: left; }
.sheet-thumb canvas { display: block; width: 100%; height: auto; border-radius: 8px; }
.sheet-thumb span { display: block; font-size: 13px; line-height: 18px; color: var(--muted); padding: 6px 4px 2px; }
.zoom { max-height: 70vh; overflow: auto; margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; }
.zoom canvas { display: block; width: 100%; height: auto; border: none; border-radius: 0; }
.pad:has(.zoom) { max-width: min(96vw, 900px); }
.slots { display: flex; gap: 10px; overflow-x: auto; margin-bottom: 16px; padding: 2px; }
.slot {
  flex: 0 0 auto; min-width: 132px; min-height: 64px; text-align: left; border: 2px solid var(--line); border-radius: 16px;
  background: #fff; padding: 8px 14px; cursor: pointer; display: flex; flex-direction: column;
}
.slot span { font-size: 14px; line-height: 20px; color: var(--muted); }
.slot small { font-size: 13px; font-weight: 700; color: var(--primary); }
.slot[aria-selected="true"] { border-color: var(--primary); background: var(--tab-bg); }
.steps a { color: inherit; text-decoration: none; }

/* 사진 가져오기 */
.pick { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.photo-layout { display: grid; grid-template-columns: 1.1fr 1fr; gap: 24px; align-items: start; }
.photo-stage { position: relative; background: #F1F0F6; border-radius: var(--radius); overflow: hidden; touch-action: none; }
.photo-stage canvas { display: block; width: 100%; height: auto; }
.panel { border: 2px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel h2 { font-size: 21px; line-height: 30px; font-weight: 700; }
.panel .preview { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.panel .preview canvas { display: block; width: 100%; height: auto; }
.status { margin-top: 8px; }
.status.warn { color: var(--warn); font-weight: 700; }
.row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.empty-box {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 40px 24px; text-align: center; color: var(--muted);
}

/* 글자 확인 */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.tile {
  border: 2px solid var(--line); border-radius: 20px; background: #fff; padding: 12px; display: flex;
  flex-direction: column; gap: 10px;
}
.tile.approved { border-color: var(--primary); }
.tile.flagged { border-color: var(--warn); }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-char { font-size: 22px; font-weight: 800; min-width: 28px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pair figure { margin: 0; }
.pair canvas { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.pair figcaption { font-size: 13px; line-height: 18px; color: var(--muted); text-align: center; margin-top: 2px; }
.tile-msg { font-size: 14px; line-height: 20px; color: var(--warn); font-weight: 700; min-height: 20px; }
.tile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tile-actions .btn { flex: 1 1 auto; padding: 0 12px; font-size: 15px; white-space: nowrap; }

/* 아래 고정 줄: 저장·다음 단추는 항상 같은 자리 */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: #fff; border-top: 1px solid var(--line);
  padding: 12px max(20px, env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.bottom-bar .count { font-weight: 700; }

/* 작품 편집 */
.editor { display: grid; grid-template-columns: 1.45fr 1fr; gap: 24px; align-items: start; }
.editor.tall { grid-template-columns: 1fr 1fr; }
.editor.tall .stage canvas { max-height: calc(100vh - 230px); width: auto; max-width: 100%; margin: 0 auto; }
.stage { background: #F1F0F6; border-radius: var(--radius); padding: 14px; position: sticky; top: 76px; }
.stage canvas { display: block; width: 100%; height: auto; border-radius: 12px; background: #fff; }
.tools .lab { display: block; font-weight: 700; margin: 4px 0 6px; }
.optrow { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.opt {
  min-width: 48px; min-height: 48px; padding: 0 14px; border-radius: 14px; border: 2px solid var(--line); background: #fff;
  font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.opt.on { border-color: var(--primary); background: var(--tab-bg); color: var(--primary); }
.opt:focus-visible { outline: 3px solid var(--banner); outline-offset: 2px; }
.opt img { display: block; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(41, 37, 71, .25); display: block; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* 내보내기 */
.export { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.exlist { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.exlist li { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-weight: 700; }

/* 내 글꼴 */
.font-layout { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: start; }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-weight: 700; margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--line); background: #fff;
}
.field textarea { min-height: 96px; resize: vertical; }
.specimen {
  border-radius: var(--radius); background: #FFFDF4; border: 2px solid var(--butter); padding: 24px;
  font-size: 64px; line-height: 1.35; min-height: 190px; word-break: break-all; white-space: pre-wrap;
}
.specimen .missing { font-family: var(--font); font-size: .55em; color: var(--muted); border-bottom: 3px dotted var(--rose); }
.note { margin-top: 12px; }
.note.warn { color: var(--warn); font-weight: 700; }
.note.ok { color: var(--primary); font-weight: 700; }
.charlist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.charlist span { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: #F1F0F6; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 20; background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 16px; max-width: min(90vw, 520px); text-align: center;
}

/* 다시 쓰기 판 */
.pad { border: none; border-radius: 24px; padding: 20px; max-width: min(94vw, 460px); width: 100%; color: var(--ink); }
.pad::backdrop { background: rgba(41, 37, 71, .45); }
.pad h2 { font-size: 21px; line-height: 30px; font-weight: 700; }
.pad p { color: var(--muted); margin-top: 4px; }
.pad .board { position: relative; margin: 14px auto; width: min(100%, 330px); }
.pad canvas { display: block; width: 100%; height: auto; border: 2px solid var(--ink); border-radius: 12px; background: #fff; touch-action: none; }
.pad .guide { position: absolute; left: 10px; top: 4px; font-size: 28px; color: #B9B7C9; pointer-events: none; }
.pad .row { justify-content: space-between; }

@media (max-width: 900px), (orientation: portrait) {
  .banner { grid-template-columns: 1fr; padding: 24px; }
  .banner h1 { font-size: 30px; line-height: 40px; }
  .banner img { max-width: 420px; margin: 0 auto; }
  .cards, .sets { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .photo-layout, .font-layout, .editor, .export { grid-template-columns: 1fr; }
  .stage { position: static; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .specimen { font-size: 48px; }
}
@media (max-width: 520px) {
  .topbar { gap: 8px; }
  .brand { font-size: 17px; }
  .tabs a { padding: 0 14px; }
  .tile-actions { flex-direction: column; }
}
@media (prefers-reduced-motion: no-preference) {
  .done-pop { animation: pop .35s ease-out 1; }
  @keyframes pop { from { transform: scale(.96); opacity: .4; } to { transform: none; opacity: 1; } }
}
