:root {
  --bg: #FFF8EC;
  --primary: #FFB84D;
  --primary-dark: #F29A1F;
  --text: #4A3B35;
  --card: #FFFFFF;
  --line: #F0E2C8;
  --err: #D94F4F;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; }
img { -webkit-user-drag: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
input, textarea { font: inherit; color: var(--text); -webkit-user-select: text; user-select: text; }
h1 { margin: 0; font-size: 26px; }

.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* buttons */
.btn {
  min-height: 64px; padding: 0 28px; border-radius: 32px; background: var(--primary);
  font-size: 22px; font-weight: 800; box-shadow: 0 5px 0 var(--primary-dark);
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn.secondary { background: #fff; box-shadow: 0 5px 0 var(--line); border: 2px solid var(--line); }
.btn.danger { background: #F58A8A; box-shadow: 0 5px 0 #D96666; }
.icon-btn {
  position: relative; width: 56px; height: 56px; flex: none; border-radius: 50%; background: #fff;
  border: 2px solid var(--line); display: grid; place-items: center; padding: 0;
}
.icon-btn img { width: 30px; height: 30px; }
.nav-btn {
  width: 72px; height: 72px; flex: none; border-radius: 50%; background: #fff; border: 3px solid var(--line);
  display: grid; place-items: center; padding: 0;
}
.nav-btn img { width: 38px; height: 38px; }
.nav-btn:disabled { opacity: .3; }
.mic-btn {
  width: 96px; height: 96px; flex: none; border-radius: 50%; background: var(--primary);
  box-shadow: 0 6px 0 var(--primary-dark); display: grid; place-items: center; padding: 0;
}
.mic-btn img { width: 52px; height: 52px; }
.mic-btn:active { transform: translateY(3px); }
.mic-btn.waiting, .pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 0 var(--primary-dark), 0 0 0 0 rgba(255,184,77,.7); }
  50% { transform: scale(1.08); box-shadow: 0 6px 0 var(--primary-dark), 0 0 0 18px rgba(255,184,77,0); }
}

/* parent gate ring */
@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }
.gate-ring {
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: conic-gradient(rgba(255,184,77,.65) calc(var(--p) * 1turn), transparent 0);
  animation: gate-fill 2s linear forwards;
}
@keyframes gate-fill { from { --p: 0; } to { --p: 1; } }

/* setup */
.setup { align-items: center; justify-content: center; padding: 24px; }
.setup-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.setup-card label { text-align: left; font-weight: 700; }
.setup-card input { height: 60px; border-radius: 16px; border: 3px solid var(--line); padding: 0 16px; font-size: 20px; background: #fff; }
.muted { color: #8a7a70; margin: 0; }
.error { color: var(--err); font-weight: 700; margin: 0; }

/* library */
.lib-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 6px; }
.lib-head h1 { flex: 1; }
.lib-grid {
  flex: 1; overflow-y: auto; padding: 10px 14px 24px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-content: start;
}
.tile-new {
  min-height: 170px; border-radius: 22px; background: var(--primary); box-shadow: 0 6px 0 var(--primary-dark);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-size: 22px; font-weight: 800; padding: 10px;
}
.tile-new img { width: 64px; height: 64px; }
.card {
  position: relative; border-radius: 22px; background: var(--card); border: 3px solid var(--line);
  overflow: hidden; display: flex; flex-direction: column; min-height: 170px; touch-action: pan-y; cursor: pointer;
}
.card .cover { border-bottom: 3px solid var(--line); pointer-events: none; }
.card .ctitle {
  padding: 8px 10px; font-size: 18px; font-weight: 800; line-height: 1.3; text-align: center;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.hint { text-align: center; font-size: 22px; font-weight: 700; padding: 0 24px 40px; margin: 0; color: #8a7a70; }

/* viewer */
.v-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; min-height: 64px; }
.v-title { flex: 1; text-align: center; font-weight: 800; font-size: 17px; line-height: 1.2; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.v-area { flex: 1; min-height: 0; display: flex; flex-direction: column; touch-action: pan-y; }
.stage-wrap { transition: opacity .15s ease; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.stage-wrap.fading, .page-text.fading { opacity: 0; }
.page-text {
  flex: 0 0 auto; min-height: 4.6em; margin: 0; padding: 8px 16px 2px; display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: clamp(19px, 5.4vw, 23px); font-weight: 800; line-height: 1.45; word-break: keep-all;
  overflow: visible; transition: opacity .15s ease;
}
.dots { display: flex; justify-content: center; align-items: center; gap: 8px; min-height: 22px; padding: 2px 0 6px; font-weight: 700; color: #8a7a70; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--primary-dark); transform: scale(1.3); }
.v-bottom { display: flex; align-items: center; justify-content: space-around; padding: 6px 16px 14px; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(74,59,53,.6); display: flex; align-items: center; justify-content: center; padding: 20px; }
.listen-box { text-align: center; color: #fff; font-size: 24px; font-weight: 800; width: 100%; }
.listen-mic { width: 130px; height: 130px; margin: 0 auto 18px; border-radius: 50%; background: var(--primary); display: grid; place-items: center; animation: pulse 1.1s ease-in-out infinite; }
.listen-mic img { width: 70px; height: 70px; }
.bubble { min-height: 64px; background: #fff; color: var(--text); border-radius: 20px; padding: 14px 18px; font-size: 24px; line-height: 1.4; margin-bottom: 12px; word-break: keep-all; }
.bubble:empty { visibility: hidden; }
.think-box { width: 100%; max-width: 360px; background: var(--bg); border-radius: 26px; padding: 14px; text-align: center; font-size: 22px; font-weight: 800; }
.think-box .stage { border-radius: 18px; }
.sheet { width: 100%; max-width: 420px; background: var(--bg); border-radius: 26px; padding: 20px; display: flex; flex-direction: column; gap: 14px; max-height: 90vh; overflow-y: auto; }
.sheet h2 { margin: 0; font-size: 24px; }
.sheet p { margin: 0; font-size: 18px; line-height: 1.5; }
.sheet input, .sheet textarea { width: 100%; border-radius: 16px; border: 3px solid var(--line); padding: 12px 14px; font-size: 20px; background: #fff; }
.sheet textarea { resize: none; }
.sheet-btns { display: flex; gap: 12px; }
.sheet-btns .btn { flex: 1; padding: 0 12px; }
.seg { display: flex; gap: 10px; }
.seg .btn { flex: 1; min-height: 56px; font-size: 20px; }
.seg .btn.on { background: var(--primary); box-shadow: 0 5px 0 var(--primary-dark); border-color: var(--primary); }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 80; background: #4A3B35; color: #fff; padding: 14px 18px; border-radius: 18px; font-size: 18px; text-align: center; font-weight: 700; }

/* reply bubble ("off" read mode: the parent reads aloud) */
.reply-bubble { margin: 4px 16px 6px; padding: 12px 16px; background: #fff; border: 3px solid var(--line); border-radius: 22px;
  font-size: clamp(18px, 5vw, 22px); font-weight: 800; line-height: 1.4; text-align: center; word-break: keep-all; color: var(--text); }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap .btn { flex: 1 1 30%; padding: 0 8px; font-size: 18px; }
.range { width: 100%; }
.sheet input[type="range"] { padding: 0; border: 0; min-height: 36px; background: transparent; }
.hint-line { font-size: 15px !important; color: #8a7a70; }
