:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --card: #ffffff;
  --ink: #191919;
  --muted: #6b6b6b;
  --faint: #9a978f;
  --line: #e6e3db;
  --accent: #1f2a44;
  --accent-ink: #ffffff;
  --soft: #f0eee8;
  --danger: #b42318;
  --loading: #fff4c2;
  --now: #ffe066;
  --radius: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.site, main, .top-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ---- 제목 ---- */
.site { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: 14px; }
.site h1 { margin: 0; font-size: 26px; line-height: 1.3; letter-spacing: -0.03em; display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 1.45em; height: 1.45em; flex: none; border-radius: 0.34em; box-shadow: 0 3px 10px rgba(31, 42, 68, 0.22); }
.site p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

/* 남색 바탕 + 흰 굵은 글씨 (앱으로 설치, ＋ 새 글) */
.chip.accent { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.accent:active { background: var(--accent); opacity: 0.85; }
.chip.install { margin-top: 12px; }
.open-edge { display: inline-block; margin-left: 6px; font-weight: 700; color: #7a4b00; text-decoration: underline; }

.chip.edge-chip { margin-top: 12px; margin-left: 4px; display: inline-flex; align-items: center; gap: 6px; background: #e8f3fc; color: #0c59a4; font-weight: 600; }

/* ---- Edge 받기 안내 창 ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(15, 18, 28, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}
.modal { grid-template-columns: minmax(0, 1fr); }
.modal-box {
  position: relative;
  justify-self: center;
  min-width: 0;
  width: min(440px, 100%);
  background: linear-gradient(180deg, #f1f8fe 0%, #ffffff 38%);
  border-radius: 22px;
  padding: 28px 22px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  text-align: center;
}
.modal-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--muted);
  font-size: 15px;
}
.edge-logo { display: block; margin: 0 auto 12px; }
.modal-box h2 { margin: 0; font-size: 21px; letter-spacing: -0.02em; }
.modal-box .lead { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.modal-box .lead b { color: var(--ink); }
.why { margin-top: 16px; text-align: left; background: var(--bg); border-radius: 14px; padding: 12px 14px; font-size: 14px; }
.why p { margin: 4px 0 0; color: var(--muted); line-height: 1.6; }
.why p b { color: var(--ink); }
.steps { margin: 14px 0 0; padding-left: 22px; text-align: left; font-size: 14px; color: var(--muted); line-height: 1.8; }
.steps b { color: var(--ink); }
.primary.edge-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  text-align: center;
  text-decoration: none;
  background: #0c59a4;
  padding: 14px 16px;
  font-size: 16px;
  border-radius: 12px;
}
.edge-open { display: block; margin-top: 12px; color: #0c59a4; font-size: 14px; font-weight: 600; text-decoration: none; }
.edge-hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.edge-later { margin-top: 10px; border: 0; background: none; color: var(--faint); font-size: 13px; padding: 6px; text-decoration: underline; }
body.modal-open { overflow: hidden; }

/* ---- MP3 저장 창 (내려받기 앱처럼: 원형 진행률 + 상태) ---- */
.sheet { text-align: left; padding-top: 24px; }
.sheet h2 { padding-right: 40px; }
.sheet .lead { margin-top: 4px; }
.file-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  transition: background-color 0.25s, border-color 0.25s;
}
.file-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 2px; }
.file-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info { font-size: 13px; color: var(--muted); }
.file-status { font-size: 13px; color: var(--muted); min-height: 1.4em; overflow-wrap: anywhere; }
.ring { position: relative; width: 64px; height: 64px; flex: none; }
.ring svg { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 6; }
.ring-track { stroke: #e3e0d8; }
.ring-fill {
  stroke: #0c59a4;
  stroke-linecap: round;
  stroke-dasharray: 175.93;
  stroke-dashoffset: 175.93;
  transition: stroke-dashoffset 0.3s ease, stroke 0.25s;
}
.ring-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.file-card.idle .ring-text { font-size: 12px; color: var(--muted); }
/* 준비 중: 고리가 빙글빙글 */
.file-card.preparing .ring svg { animation: spin 0.9s linear infinite; }
.file-card.preparing .ring-fill { stroke-dashoffset: 132; }
@keyframes spin { to { transform: rotate(270deg); } }
.file-card.working { background: #f3f8fd; border-color: #cfe2f4; }
.file-card.working .file-status { color: #0c59a4; font-weight: 600; }
.file-card.done { background: #eef8f1; border-color: #bfe3cb; }
.file-card.done .ring-fill { stroke: #1f7a3a; }
.file-card.done .ring-text { color: #1f7a3a; font-size: 24px; }
.file-card.done .file-status { color: #1f7a3a; font-weight: 600; }
.file-card.error { background: #fdf0ef; border-color: #f2c9c4; }
.file-card.error .ring-fill { stroke: var(--danger); }
.file-card.error .ring-text { color: var(--danger); font-size: 22px; }
.file-card.error .file-status { color: var(--danger); font-weight: 600; }
.sheet-fields { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.sheet-fields .field.grow { flex: 1 1 160px; }
.sheet-fields select:disabled { opacity: 0.55; }
.primary.edge-btn.save-file { background: #1f7a3a; }
.primary.edge-btn.save-file.saved { background: #e6f4ea; color: #1f7a3a; }
#saveGo.cancel { background: var(--soft); color: var(--ink); }

main { padding-bottom: max(14px, env(safe-area-inset-bottom)); }

/* ---- 카드 ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(20, 20, 20, 0.03);
}
.row { display: flex; align-items: center; gap: 10px; }
.row + .row { margin-top: 12px; }
.row.wrap { flex-wrap: wrap; row-gap: 10px; }
.row.between { justify-content: space-between; }

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  min-width: 0;
}
.field.grow { flex: 1 1 150px; }
.field.full { width: 100%; }
.field.full select, .field.grow select { flex: 1; min-width: 0; }

select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b6b6b' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 10px center;
  border-radius: 10px;
  height: 38px;
  padding: 0 28px 0 11px;
  font-size: 15px;
  color: var(--ink);
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.rate-sel { width: 84px; flex: none; }

.primary, .ghost, .chip, .link {
  border: 0;
  border-radius: 10px;
  white-space: nowrap;
}
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; padding: 9px 16px; }
.primary:active { opacity: 0.85; }
.ghost { background: var(--soft); padding: 9px 12px; font-size: 14px; }
.ghost:active { background: #e5e2da; }
.play-btn { min-width: 92px; }
.progress { margin-left: auto; font-weight: 700; color: var(--muted); font-size: 14px; white-space: nowrap; text-align: right; }
.player .row:first-child { flex-wrap: wrap; row-gap: 8px; }

/* 처음부터 · 이전 문장 · 다음 문장 (한 덩어리) */
.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 2px; gap: 2px; flex: none; }
.seg button {
  border: 0;
  background: none;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 14px;
  white-space: nowrap;
  color: var(--ink);
}
.seg button:hover { background: rgba(255, 255, 255, 0.7); }
.seg button:active { background: #fff; transform: scale(0.97); }

.link { background: none; color: var(--muted); padding: 4px 2px; font-size: 14px; }
.link:hover { color: var(--ink); }
.nav { min-height: 30px; }
.nav .link[hidden] { display: inline-block !important; visibility: hidden; }

.meta { margin-top: 6px; padding-top: 10px; border-top: 1px dashed var(--line); flex-wrap: wrap; row-gap: 8px; }
.count { color: var(--muted); font-size: 13px; }
.count b { color: var(--ink); }
.tools { display: inline-flex; gap: 6px; }
.chip { background: var(--soft); padding: 5px 11px; font-size: 13px; border-radius: 999px; }
.chip:active { background: #e5e2da; }
.chip.danger { color: var(--danger); }

/* ---- 본문 ---- */
.doc {
  padding: 18px 18px 6px;
  font-size: 18px;
  line-height: 1.85;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.doc p { margin: 0 0 1.15em; }
.s {
  color: var(--ink);
  border-radius: 5px;
  padding: 2px 1px;
  margin: 0 -1px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  cursor: pointer;
}
.s.hover, .s.pending { background: var(--loading); color: #000; }
.s.now { background: var(--now); color: #000; font-weight: 700; }

/* ---- 글 넣기 ---- */
.editor h2 { margin: 0; font-size: 17px; }
.editor textarea {
  display: block;
  width: 100%;
  min-height: 50vh;
  margin-top: 12px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fdfdfb;
  padding: 14px;
  line-height: 1.7;
  font-size: 16px;
  outline: none;
}
.editor textarea:focus { border-color: #c9c4b8; background: #fff; }
.editor .actions { margin-top: 12px; }

.credit { text-align: center; color: var(--faint); font-size: 12px; padding: 6px 2px 0; }
.credit a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
.credit a:hover { color: var(--ink); border-color: var(--muted); }

/* 최상단 오른쪽: 개발자 블로그 (흰 카드의 오른쪽 끝에 맞춤, 위에 붙는 메뉴에는 없음) */
.site-top { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.blog-link { font-size: 13px; color: var(--muted); text-decoration: none; padding: 4px 0; }
.blog-link:hover { color: var(--ink); text-decoration: underline; }

/* ---- 위에 붙는 간단 메뉴 ---- */
.compact {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: rgba(247, 246, 242, 0.94);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  transform: translateY(-110%);
  transition: transform 0.18s ease;
}
.compact.show { transform: none; }
.compact-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.compact-row { display: flex; align-items: center; gap: 8px; }
.compact .play-btn { min-width: 84px; padding: 8px 12px; }
.compact .seg button { padding: 7px 12px; font-size: 15px; }
.compact .voice-sel { flex: 1 1 auto; }
.compact .progress { margin-left: auto; }
@media (min-width: 640px) {
  /* 넓은 화면: 한 줄로 [재생][⏮ ‹ ›][속도][목소리 ……][N / M 문장] */
  .compact-inner { flex-direction: row; align-items: center; }
  .compact-row { display: contents; }
  .compact .voice-sel { flex: 0 1 320px; }
  .compact .progress { order: 99; margin-left: auto; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: calc(100% - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
  background: #2b2b2b;
  color: #fff;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.toast button { background: none; border: 0; color: #ffd84d; font-weight: 700; padding: 0; }

@media (max-width: 420px) {
  .site h1 { font-size: 23px; }
  .doc { font-size: 17px; padding: 16px 15px 4px; }
  .player .seg .tx { display: none; }
}
@media (min-width: 760px) {
  .site h1 { font-size: 30px; }
  .doc { padding: 26px 30px 10px; font-size: 19px; }
}
