/* Indelible: 공책 종이 + 잉크 남색, 재질 펜 4색 */
:root {
  --paper: #FBF6EA;
  --paper-line: #D9E5F1;
  --paper-margin: #F0A9A9;
  --ink: #23304A;
  --ink-soft: #3C4A66;
  --card: #FFFDF7;
  --wood: #9A6232;
  --rubber: #D93A72;
  --ice: #2EA6D6;
  --fire: #FF6A1A;
  --balloon: #8A4FE0;
  --water: #2C6FE8;
  --magnet: #C62828;
  --ball: #23304A;
  --goal: #E8A317;
  --bubble: #FFFFFF;
  --bubble-ink: #23304A;
  --accent: #2F5BD8;
  --shadow: 0 6px 20px rgba(35, 48, 74, 0.16);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1B2130;
    --paper-line: #28324A;
    --paper-margin: #5A3440;
    --ink: #E7ECF5;
    --ink-soft: #C3CCDD;
    --card: #232A3B;
    --wood: #C68E5C;
    --rubber: #E8719A;
    --ice: #6CCBEE;
    --fire: #FF8A3D;
    --balloon: #B58CF5;
    --water: #6FA6FF;
    --magnet: #F06A6A;
    --ball: #F1F4FA;
    --goal: #F2C14E;
    --bubble: #2E3750;
    --bubble-ink: #F1F4FA;
    --accent: #8FB0FF;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1B2130;
  --paper-line: #28324A;
  --paper-margin: #5A3440;
  --ink: #E7ECF5;
  --ink-soft: #C3CCDD;
  --card: #232A3B;
  --wood: #C68E5C;
  --rubber: #E8719A;
  --ice: #6CCBEE;
  --fire: #FF8A3D;
  --balloon: #B58CF5;
  --water: #6FA6FF;
  --magnet: #F06A6A;
  --ball: #F1F4FA;
  --goal: #F2C14E;
  --bubble: #2E3750;
  --bubble-ink: #F1F4FA;
  --accent: #8FB0FF;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input { font-size: 16px; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* 상단 바 */
.top {
  display: flex; align-items: center; gap: 8px;
  width: 100%; max-width: 720px; align-self: center;
  padding: 8px 12px; min-height: 52px;
}
.chip {
  display: flex; align-items: baseline; gap: 6px;
  border: 2px solid var(--ink); border-radius: 999px;
  background: var(--card); padding: 6px 12px;
  font-size: 15px; white-space: nowrap;
}
.chip span { font-weight: 600; opacity: 0.85; }
.chip b { font-weight: 800; }
.ink { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 60px; }
.ink-label { font-size: 13px; font-weight: 700; }
.ink-bar { flex: 1; height: 10px; border-radius: 6px; border: 2px solid var(--ink); overflow: hidden; background: var(--card); }
.ink-bar i { display: block; height: 100%; width: 100%; background: var(--accent); transition: width 0.12s linear; }
.ink-bar i.low { background: var(--fire); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: none;
  background: var(--card); box-shadow: var(--shadow); font-size: 18px; flex: none;
}

/* 판 */
#stageWrap { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; display: block; touch-action: none; }
#hint {
  position: absolute; left: 50%; bottom: 8px; transform: translate(-50%, 8px);
  width: min(92%, 380px);
  background: var(--card); border: 2px solid var(--ink); border-radius: 14px;
  padding: 10px 12px; font-size: 15px; line-height: 1.45; font-weight: 600;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#hint.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#hint.show ~ #toast { bottom: auto; top: 30%; }
#toast {
  position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 10px);
  max-width: 92%; background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 999px; font-size: 15px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.blank-btn {
  position: absolute; right: 10px; top: 10px; z-index: 2;
  background: var(--card); color: var(--ink); border: 2px dashed var(--ink); border-radius: 999px;
  padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 700; box-shadow: var(--shadow);
}
.blank-btn.arm { background: var(--ink); color: var(--paper); border-style: solid; }

/* 하단 펜 바 */
.dock {
  position: relative; z-index: 3; flex: none;
  display: flex; align-items: stretch; gap: 8px;
  width: min(100% - 20px, 560px); align-self: center;
  margin: 6px 10px calc(10px + env(safe-area-inset-bottom));
  padding: 8px; border-radius: 20px;
  background: var(--card); box-shadow: var(--shadow);
}
.pens { flex: 1; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.pen {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; border-radius: 14px; border: 2px solid transparent; background: transparent;
  font-size: 14px; font-weight: 700;
}
.pen span { white-space: nowrap; }
/* 펜이 5개 이상인 장: 버튼을 조금씩 줄인다 */
.dock[data-n="5"] .act, .dock[data-n="6"] .act, .dock[data-n="7"] .act { width: 50px; }
.dock[data-n="5"] .pen, .dock[data-n="6"] .pen, .dock[data-n="7"] .pen { font-size: 12.5px; }
.dock[data-n="5"] .dot, .dock[data-n="6"] .dot, .dock[data-n="7"] .dot { width: 20px; }
.pen.on { border-color: var(--ink); background: var(--paper); }
.dot { width: 26px; height: 8px; border-radius: 6px; display: block; }
.dot.wood { background: var(--wood); }
.dot.rubber { background: var(--rubber); }
.dot.ice { background: var(--ice); }
.dot.balloon { background: var(--balloon); height: 10px; border-radius: 8px; box-shadow: inset 3px -2px 0 rgba(255,255,255,0.45); }
.dot.water { background: repeating-linear-gradient(90deg, var(--water) 0 6px, transparent 6px 9px); border-radius: 6px; }
.dot.magnet { background: linear-gradient(90deg, var(--magnet) 0 50%, #9AA3AE 50% 100%); }
.dot.fire { background: linear-gradient(90deg, var(--fire), #FFD36B); }
.act {
  width: 62px; border-radius: 14px; border: 2px solid var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; background: var(--paper); flex: none;
}
.act span { font-size: 13px; }
.go.ready { background: var(--ink); color: var(--paper); }
.go:disabled { opacity: 0.4; }
.retry.pulse { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { background: var(--goal); } }

@media (max-height: 680px) {
  .pen { min-height: 46px; }
  .top { min-height: 46px; padding: 4px 10px; }
  .icon-btn { width: 36px; height: 36px; }
}

/* 겹창 */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.hidden { display: none !important; }
.card {
  position: relative; width: min(100%, 420px);
  background: var(--card); border: 2px solid var(--ink); border-radius: 24px;
  padding: 22px 20px 16px; box-shadow: var(--shadow); text-align: center;
  margin: auto;
}
.close { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border-radius: 10px; border: none; background: transparent; font-size: 18px; }
.logo svg { width: 120px; height: 60px; color: var(--accent); }
.logo-ball { fill: var(--ink); }
h1 { font-size: 25px; margin: 6px 0 0; letter-spacing: -0.5px; }
h2 { font-size: 23px; margin: 0; }
.en { margin: 2px 0 8px; font-weight: 700; opacity: 0.75; letter-spacing: 2px; }
.lead { font-size: 16px; line-height: 1.5; margin: 6px 0 14px; font-weight: 500; }
.hello-row { display: flex; justify-content: center; align-items: center; gap: 6px; font-size: 18px; font-weight: 800; margin-bottom: 10px; }
.link { border: none; background: none; font-size: 16px; }
.name-row { margin-bottom: 10px; }
#nameInput {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--ink);
  background: var(--paper); color: var(--ink); text-align: center; font-weight: 700;
  -webkit-user-select: text; user-select: text;
}
#nameInput.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.big {
  display: block; width: 100%; margin: 8px 0; padding: 14px; border-radius: 16px;
  border: 2px solid var(--ink); background: var(--ink); color: var(--paper);
  font-size: 18px; font-weight: 800;
}
.big.sub { background: transparent; color: var(--ink); }
.howto { text-align: left; padding: 0; margin: 14px 0 6px; list-style: none; font-size: 14px; line-height: 1.5; }
.howto li { margin: 6px 0; }
.howto b { display: inline-block; min-width: 38px; }
.version { font-size: 12px; font-weight: 600; opacity: 0.7; margin: 10px 0 0; }
.end-pic { max-height: 42vh; overflow-y: auto; border-radius: 14px; border: 2px solid var(--ink); margin: 6px 0 10px; }
.end-pic canvas { display: block; width: 100%; height: auto; }
.stats { text-align: left; margin: 0 0 8px; padding-left: 18px; font-size: 15px; line-height: 1.55; font-weight: 600; }

/* 책장: 공책 고르기 */
.shelf { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.book {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; border-radius: 14px; border: 2px solid transparent;
  background: var(--paper); min-height: 56px;
}
.book.on { border-color: var(--ink); }
.book.locked { opacity: 0.6; }
.book .spine { flex: none; width: 14px; height: 40px; border-radius: 4px; background: var(--accent); box-shadow: inset -3px 0 0 rgba(0,0,0,0.18); }
.book .spine.b2 { background: var(--balloon); }
.book .spine.b3 { background: var(--water); }
.book .spine.b4 { background: var(--magnet); }
.book .bt { display: flex; flex-direction: column; gap: 2px; }
.book b { font-size: 16px; font-weight: 800; }
.book small { font-size: 13px; font-weight: 600; opacity: 0.85; }
