/* 한붓 팡 화면 — 공책·연필(종이 미색·파랑 잉크) */
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: #141a33; overflow: hidden; position: fixed;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: rgba(0,0,0,0);
  -webkit-text-size-adjust: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  color: #f3f6ff;
}
* { box-sizing: border-box; }
button {
  font-family: inherit; border: 0; cursor: pointer; color: inherit;
  touch-action: manipulation; -webkit-appearance: none; appearance: none;
}
.hidden { display: none !important; }

#app {
  position: absolute; left: 0; top: 0; right: 0; bottom: 0;
  background: #141a33;
  background: -webkit-linear-gradient(top, #223a7a 0%, #1a2756 50%, #141a33 100%);
  background: linear-gradient(180deg, #223a7a 0%, #1a2756 50%, #141a33 100%);
}
.screen {
  position: absolute; left: 0; top: 0; right: 0; bottom: 0;
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ===== 공통 버튼 ===== */
.iconBtn {
  min-width: 56px; height: 56px; border-radius: 18px; font-size: 26px; line-height: 1;
  background: #fdf6e3; color: #1f3f99; font-weight: 900;
  box-shadow: 0 4px 0 #b9a77a, inset 0 2px 0 rgba(255,255,255,0.6);
  -webkit-flex: none; flex: none; padding: 0 10px;
  -webkit-transition: -webkit-transform 0.08s; transition: transform 0.08s;
}
.iconBtn:active, .btn:active, .lvBtn:active, .modeBtn:active, .ctlBtn:active {
  -webkit-transform: translateY(3px) scale(0.97); transform: translateY(3px) scale(0.97);
}
.btn {
  display: block; width: 100%; min-height: 58px; border-radius: 20px; margin: 10px 0 0;
  font-size: 21px; font-weight: 900; padding: 10px 16px;
  background: #e6ecfb; color: #1f3f99; box-shadow: 0 5px 0 #9fb0de;
  -webkit-transition: -webkit-transform 0.08s; transition: transform 0.08s;
}
.btn.primary { background: #ffd34d; color: #4a3500; box-shadow: 0 5px 0 #c99a12; }
.btn.ink { background: #3b63d6; color: #fff; box-shadow: 0 5px 0 #213f99; }
.btn.warn { background: #ff9f5a; color: #4a2000; box-shadow: 0 5px 0 #c4621a; }
.btn[disabled] { opacity: 0.45; }
.btnRow { display: -webkit-flex; display: flex; margin: 0 -5px; }
.btnRow .btn { margin-left: 5px; margin-right: 5px; -webkit-flex: 1; flex: 1; }

.coinPill {
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
  height: 44px; padding: 0 14px 0 8px; border-radius: 22px;
  background: rgba(0,0,0,0.3); font-size: 20px; white-space: nowrap;
}
.coinIco { font-size: 22px; margin-right: 6px; }

/* ===== 지도 ===== */
#mapTop, #gTop {
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
  padding: 8px 10px; -webkit-flex: none; flex: none;
}
#mapTitle { -webkit-flex: 1; flex: 1; min-width: 0; padding: 0 10px; }
.logo { font-size: 26px; font-weight: 900; color: #ffe27a; letter-spacing: -0.5px; white-space: nowrap; }
.sub { font-size: 13px; color: #b8c6f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topRight { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; }
.topRight > * { margin-left: 8px; }
.shopBtn { background: #ffd34d; color: #4a3500; box-shadow: 0 4px 0 #c99a12, inset 0 2px 0 rgba(255,255,255,0.4); }
.notice {
  margin: 0 12px 6px; padding: 10px 14px; border-radius: 14px; font-size: 15px; font-weight: 700;
  background: #fff1c2; color: #5a3b00;
}
.notice .btn { min-height: 48px; font-size: 17px; margin-top: 8px; }
#mapScroll {
  position: relative; -webkit-flex: 1; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 12px 40px; touch-action: pan-y;
}
#chapters, #modes { max-width: 860px; margin: 0 auto; }
.chapter {
  position: relative; margin: 10px 0 18px; border-radius: 22px; padding: 12px 12px 14px 26px;
  background-color: #fdf6e3; color: #1f3f99;
  background-image: -webkit-repeating-linear-gradient(top, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 29px, #dbe4f7 29px, #dbe4f7 30px);
  background-image: repeating-linear-gradient(180deg, rgba(0,0,0,0) 0px, rgba(0,0,0,0) 29px, #dbe4f7 29px, #dbe4f7 30px);
  border-left: 14px solid #3b63d6;
  box-shadow: 0 8px 0 rgba(0,0,0,0.28);
}
.chapter:before {
  content: ""; position: absolute; left: 12px; top: 0; bottom: 0; width: 2px; background: #f4a7a7;
}
.chapter.locked { opacity: 0.72; }
.chHead { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; margin: 0 4px 10px; }
.chIco {
  width: 48px; height: 48px; border-radius: 16px; font-size: 28px; line-height: 48px; text-align: center;
  background: #e6ecfb; margin-right: 10px; -webkit-flex: none; flex: none;
}
.chName { -webkit-flex: 1; flex: 1; font-size: 20px; font-weight: 900; color: #1f3f99; }
.chName small { display: block; font-size: 13px; font-weight: 700; color: #6a7cae; }
.chProg { font-size: 15px; font-weight: 900; color: #1f3f99; background: #e6ecfb; border-radius: 12px; padding: 5px 10px; }
.lvGrid { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; margin: -4px; }
.lvBtn {
  width: calc(25% - 8px); margin: 4px; min-height: 66px; border-radius: 18px; padding: 6px 2px;
  background: #e6ecfb; color: #1f3f99; box-shadow: 0 4px 0 #9fb0de;
  display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column;
  -webkit-align-items: center; align-items: center; -webkit-justify-content: center; justify-content: center;
  -webkit-transition: -webkit-transform 0.08s; transition: transform 0.08s;
}
.lvBtn .n { font-size: 24px; font-weight: 900; line-height: 1.1; }
.lvBtn .s { font-size: 12px; font-weight: 800; line-height: 1.2; margin-top: 2px; }
.lvBtn.done { background: #3b63d6; color: #fff; box-shadow: 0 4px 0 #213f99; }
.lvBtn.lock { background: rgba(31,63,153,0.08); color: rgba(31,63,153,0.4); box-shadow: none; }
.lvBtn.next {
  background: #ffd34d; color: #4a3500; box-shadow: 0 4px 0 #c99a12;
  -webkit-animation: nextPulse 1.1s ease-in-out infinite alternate; animation: nextPulse 1.1s ease-in-out infinite alternate;
}
@-webkit-keyframes nextPulse { from { -webkit-transform: scale(1); } to { -webkit-transform: scale(1.06); } }
@keyframes nextPulse { from { transform: scale(1); } to { transform: scale(1.06); } }
.lowfx .lvBtn.next { -webkit-animation: none; animation: none; }
@media (min-width: 640px) {
  .lvBtn { width: calc(12.5% - 8px); }
}
.modeBtn {
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
  width: 100%; min-height: 84px; margin: 0 0 14px; padding: 12px 16px; border-radius: 24px; text-align: left;
  background: #ffe8a3; color: #4a3500; box-shadow: 0 6px 0 #c99a12;
  -webkit-transition: -webkit-transform 0.08s; transition: transform 0.08s;
}
.modeBtn.endless { background: #c9d6ff; color: #1f3f99; box-shadow: 0 6px 0 #7088d0; }
.modeBtn.locked { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.65); box-shadow: none; }
.modeBtn .mIco { font-size: 38px; width: 56px; text-align: center; -webkit-flex: none; flex: none; margin-right: 10px; }
.modeBtn .mTxt { -webkit-flex: 1; flex: 1; }
.modeBtn .mName { font-size: 21px; font-weight: 900; }
.modeBtn .mSub { font-size: 14px; font-weight: 700; opacity: 0.85; margin-top: 2px; }
.modeBtn .mTag { font-size: 13px; font-weight: 900; background: rgba(0,0,0,0.12); border-radius: 10px; padding: 4px 8px; white-space: nowrap; }
.mapFoot { text-align: center; color: #b8c6f0; font-size: 14px; margin: 10px 0 0; }
.modesTitle { font-size: 18px; font-weight: 900; color: #ffe27a; margin: 18px 6px 10px; }

/* ===== 게임 화면 ===== */
#gTitle { -webkit-flex: 1; flex: 1; min-width: 0; text-align: center; padding: 0 6px; }
#gTitleMain { font-size: 21px; font-weight: 900; color: #fff6d6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#gTitleSub { font-size: 13px; font-weight: 700; color: #b8c6f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#gTop .iconBtn + .iconBtn { margin-left: 8px; }
#gStats {
  display: -webkit-flex; display: flex; -webkit-justify-content: center; justify-content: center;
  -webkit-align-items: center; align-items: center; -webkit-flex-wrap: wrap; flex-wrap: wrap;
  padding: 0 8px 6px; -webkit-flex: none; flex: none;
}
.stat {
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
  height: 44px; margin: 2px 4px; padding: 0 12px; border-radius: 22px;
  background: rgba(0,0,0,0.3); font-size: 19px; white-space: nowrap;
}
.stat .sLab { font-size: 13px; font-weight: 800; color: #b8c6f0; margin-right: 6px; }
.stat.big { background: #fdf6e3; color: #1f3f99; }
.stat.big .sLab { color: #6a7cae; }
.stat.big b { font-size: 26px; margin-left: 6px; }
.pencils { font-size: 20px; letter-spacing: -3px; }
.pencils .used { opacity: 0.22; }
.stat.warn { background: #ff8a6a; color: #fff; -webkit-animation: warnBlink 0.7s ease-in-out infinite alternate; animation: warnBlink 0.7s ease-in-out infinite alternate; }
.stat.warn .sLab { color: #fff0e8; }
.lowfx .stat.warn { -webkit-animation: none; animation: none; }
@-webkit-keyframes warnBlink { from { -webkit-transform: scale(1); } to { -webkit-transform: scale(1.08); } }
@keyframes warnBlink { from { transform: scale(1); } to { transform: scale(1.08); } }
.stat.small { font-size: 16px; padding: 0 10px; }
.stat.small b { font-size: 18px; }

#gPlay {
  -webkit-flex: 1; flex: 1; min-height: 0;
  display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column;
}
#boardCol {
  -webkit-flex: 1; flex: 1; min-height: 0; min-width: 0;
  display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column;
  padding: 0 10px;
}
#boardWrap {
  position: relative; -webkit-flex: 1; flex: 1; min-height: 0; min-width: 0;
  border-radius: 20px; overflow: hidden; background: #fdf6e3;
  box-shadow: 0 6px 0 #b9a77a, 0 10px 24px rgba(0,0,0,0.35);
  touch-action: none;
}
#board { position: absolute; left: 0; top: 0; display: block; touch-action: none; }
#rules {
  position: absolute; left: 8px; top: 8px; right: 8px; pointer-events: none;
  display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap;
}
.rule {
  display: inline-block; margin: 0 6px 6px 0; padding: 5px 10px; border-radius: 12px;
  font-size: 14px; font-weight: 900; background: rgba(255,255,255,0.88); color: #1f3f99;
  border: 2px solid #c9d6ff;
}
#toast {
  position: absolute; left: 10px; right: 10px; bottom: 12px; text-align: center; pointer-events: none;
  -webkit-transition: opacity 0.25s; transition: opacity 0.25s;
}
#toast span {
  position: relative; display: inline-block; max-width: 100%; padding: 12px 20px; border-radius: 22px; font-size: 20px; font-weight: 900;
  background: #fff; color: #1f3f99; border: 3px solid #3b63d6; box-shadow: 0 4px 0 rgba(31,63,153,0.35);
}
#toast.bad span { border-color: #ff8a6a; color: #8a2a10; }
#toast.fade { opacity: 0; }
#gHelp {
  -webkit-flex: none; flex: none; text-align: center; font-size: 16px; font-weight: 800; color: #dfe6ff;
  padding: 8px 6px 2px; min-height: 30px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#controls {
  -webkit-flex: none; flex: none;
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  padding: 8px 8px 10px;
}
.ctlBtn {
  position: relative; width: 104px; height: 84px; border-radius: 26px; margin: 0 8px;
  background: #fdf6e3; color: #1f3f99; box-shadow: 0 5px 0 #b9a77a;
  display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column;
  -webkit-align-items: center; align-items: center; -webkit-justify-content: center; justify-content: center;
  -webkit-transition: -webkit-transform 0.08s; transition: transform 0.08s;
}
.ctlBtn .cIco { font-size: 32px; line-height: 1; }
.ctlBtn .cLab { font-size: 14px; font-weight: 900; margin-top: 4px; white-space: nowrap; }
.ctlBtn .cSub { font-size: 11px; font-weight: 800; color: #6a7cae; white-space: nowrap; }
.ctlBtn.off { opacity: 0.4; }
.ctlBtn.nudge { background: #ffd34d; color: #4a3500; box-shadow: 0 5px 0 #c99a12;
  -webkit-animation: warnBlink 0.6s ease-in-out infinite alternate; animation: warnBlink 0.6s ease-in-out infinite alternate; }
.lowfx .ctlBtn.nudge { -webkit-animation: none; animation: none; }
#btnHint { background: #fff3a8; box-shadow: 0 5px 0 #c9a93a; color: #4a3500; }
#btnHint.off { opacity: 0.45; }
#btnHint.busy { opacity: 0.6; }
.badge {
  position: absolute; right: -6px; top: -8px; min-width: 30px; height: 30px; border-radius: 15px; padding: 0 7px;
  background: #3b63d6; color: #fff; font-size: 15px; font-weight: 900; line-height: 30px; text-align: center;
  box-shadow: 0 2px 0 rgba(0,0,0,0.3); white-space: nowrap;
}
.badge.zero { background: #9a9ab0; }
.badge.stamp { background: #e0453a; }

/* 가로 화면: 오른쪽에 조작판 */
@media (min-aspect-ratio: 1/1) {
  #gPlay { -webkit-flex-direction: row; flex-direction: row; }
  #boardCol { padding: 0 0 8px 10px; }
  #controls {
    -webkit-flex-direction: column; flex-direction: column;
    width: 148px; padding: 4px 10px 10px;
  }
  .ctlBtn { margin: 9px 0; width: 112px; }
}
/* 작은 휴대폰 */
@media (max-height: 640px), (max-width: 370px) {
  .ctlBtn { height: 72px; width: 92px; margin: 0 5px; }
  .ctlBtn .cIco { font-size: 26px; }
  .stat { height: 40px; font-size: 17px; }
  .stat.big b { font-size: 22px; }
  #gHelp { font-size: 14px; padding-top: 5px; }
}
@media (max-height: 640px) and (min-aspect-ratio: 1/1) {
  #gTop { padding: 4px 10px; }
  #controls { width: 130px; }
  .ctlBtn { margin: 5px 0; width: 104px; height: 68px; }
  .ctlBtn .cSub { display: none; }
}
@media (max-width: 400px) and (max-aspect-ratio: 1/1) {
  .ctlBtn { width: 30%; margin: 0 1.5%; }
  .stat { margin: 2px 2px; padding: 0 9px; }
  .stat .sLab { font-size: 12px; margin-right: 4px; }
  #gStats { padding-left: 4px; padding-right: 4px; }
  #toast span { font-size: 18px; padding: 10px 14px; }
  #statHints { display: none; }
}
/* 큰 태블릿 */
@media (min-width: 700px) and (min-height: 700px) {
  .ctlBtn { width: 124px; height: 96px; }
  .ctlBtn .cIco { font-size: 36px; }
  .ctlBtn .cLab { font-size: 16px; }
  #gHelp { font-size: 18px; }
}
@media (min-width: 700px) and (min-height: 700px) and (min-aspect-ratio: 1/1) {
  #controls { width: 168px; }
  .ctlBtn { width: 132px; margin: 12px 0; }
}

/* ===== 창(말풍선·결과·상점) ===== */
#modal {
  position: absolute; left: 0; top: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(10,16,40,0.62);
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  padding: 16px; padding-top: calc(16px + env(safe-area-inset-top, 0px)); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.card {
  position: relative; width: 100%; max-width: 470px; max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: #fffbef; color: #1f2f66; border-radius: 28px; border: 6px solid #3b63d6;
  padding: 18px 18px 20px; box-shadow: 0 10px 0 #213f99, 0 18px 40px rgba(0,0,0,0.4);
  -webkit-animation: popIn 0.22s ease-out; animation: popIn 0.22s ease-out;
}
.lowfx .card { -webkit-animation: none; animation: none; }
@-webkit-keyframes popIn { from { -webkit-transform: scale(0.85); opacity: 0; } to { -webkit-transform: scale(1); opacity: 1; } }
@keyframes popIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.card h2 { margin: 2px 0 10px; font-size: 26px; text-align: center; color: #1f3f99; }
.card p { margin: 8px 0; font-size: 19px; line-height: 1.45; font-weight: 700; }
.card .center { text-align: center; }
.bubble {
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; margin: 6px 0 10px;
}
.bubble canvas { -webkit-flex: none; flex: none; margin-right: 12px; }
.bubble .say {
  position: relative; -webkit-flex: 1; flex: 1; background: #e6ecfb; border-radius: 20px; padding: 14px 16px;
  font-size: 21px; font-weight: 900; line-height: 1.4; color: #1f3f99;
}
.bubble .say:before {
  content: ""; position: absolute; left: -12px; top: 50%; margin-top: -10px;
  border-width: 10px 12px 10px 0; border-style: solid; border-color: transparent #e6ecfb transparent transparent;
}
.devRow {
  display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center;
  background: #fdf3d6; border-radius: 18px; padding: 8px 12px; margin: 8px 0;
}
.devRow canvas { -webkit-flex: none; flex: none; margin-right: 12px; border-radius: 10px; }
.devRow .dTxt { font-size: 17px; font-weight: 800; line-height: 1.4; }
.devRow .newTag { display: inline-block; background: #ff8a3d; color: #fff; border-radius: 8px; font-size: 13px; padding: 2px 7px; margin-right: 6px; vertical-align: 2px; }
.chapTag { text-align: center; font-size: 15px; font-weight: 900; color: #3b63d6; margin-bottom: 2px; }

.thumbWrap { text-align: center; margin: 2px 0 4px; }
.thumbWrap canvas { border-radius: 16px; box-shadow: 0 3px 0 #d8c9a0; }
.resBig { text-align: center; font-size: 46px; font-weight: 900; color: #1f3f99; margin: 4px 0; }
.resLine {
  display: -webkit-flex; display: flex; -webkit-justify-content: space-between; justify-content: space-between;
  font-size: 19px; font-weight: 800; padding: 8px 6px; border-bottom: 2px dashed #d6def5;
}
.resLine b { font-size: 22px; }
.resCoin { text-align: center; font-size: 30px; font-weight: 900; color: #a06a00; margin: 12px 0 2px; }
.resNote { text-align: center; font-size: 16px; font-weight: 800; color: #6a7cae; }
.errBox { background: #ffe1d9; color: #8a2a10; border-radius: 14px; padding: 10px 12px; font-size: 17px; font-weight: 800; text-align: center; margin-top: 10px; }
.spinner { text-align: center; font-size: 20px; font-weight: 900; color: #3b63d6; margin: 14px 0; }

/* 상점 */
.card.shop { max-width: 620px; }
.shopHead { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; margin-bottom: 8px; }
.shopHead h2 { -webkit-flex: 1; flex: 1; text-align: left; margin: 0; }
.shopHead .coinPill { background: #fdf3d6; color: #4a3500; }
.shopMsg { background: #e6ecfb; color: #1f3f99; border-radius: 14px; padding: 9px 12px; font-size: 16px; font-weight: 800; margin: 6px 0; text-align: center; }
.shopMsg.bad { background: #ffe1d9; color: #8a2a10; }
.items { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; margin: 0 -5px; }
.item {
  width: calc(50% - 10px); margin: 5px; background: #fdf3d6; border-radius: 20px; padding: 10px 8px 10px;
  text-align: center;
}
.item.wide { width: calc(100% - 10px); display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; text-align: left; }
.item.wide .iBody { -webkit-flex: 1; flex: 1; padding-left: 10px; }
.item.on { background: #dfe7ff; box-shadow: inset 0 0 0 3px #3b63d6; }
.item canvas { display: block; margin: 0 auto; border-radius: 14px; }
.item.wide canvas { margin: 0; -webkit-flex: none; flex: none; }
.iName { font-size: 16px; font-weight: 900; margin: 4px 0 2px; }
.iSub { font-size: 13px; font-weight: 700; color: #6a7cae; }
.item .btn { min-height: 56px; font-size: 18px; margin-top: 8px; border-radius: 16px; }
.btn.using { opacity: 1; background: #3b63d6; color: #fff; box-shadow: 0 5px 0 #213f99; }
@media (min-width: 560px) { .item { width: calc(33.33% - 10px); } }
