/* 별이 빛나는 밤 퍼즐 — 스타일 (외부 글꼴·CDN 없이 오프라인 동작) */
:root {
  --night-0: #050b24;
  --night-1: #0a1538;
  --night-2: #13245c;
  --blue: #3b6fd8;
  --sky: #8fc6ff;
  --star: #ffd23f;
  --star-soft: #fff1a8;
  --ink: #f4f7ff;
  --ink-dim: #aebbe0;
  --card: rgba(16, 30, 78, 0.92);
  --line: rgba(160, 190, 255, 0.22);
  --danger: #ef4c5a;
  --tb-h: 52px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none;
  background: var(--night-0); color: var(--ink); font-family: var(--font);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--star); outline-offset: 2px; }
[hidden] { display: none !important; }

#sky { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
/* 반짝이는 별(십자 빛) */
#twinkles { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
#twinkles i { position: absolute; width: var(--sz); height: var(--sz); transform: translate(-50%, -50%); animation: twinkle 4s ease-in-out infinite; opacity: 0.2;
  background: radial-gradient(circle, #fff8d8 0 14%, transparent 15%), linear-gradient(90deg, transparent 44%, rgba(255, 244, 200, 0.95) 50%, transparent 56%), linear-gradient(0deg, transparent 44%, rgba(255, 244, 200, 0.95) 50%, transparent 56%);
  border-radius: 50%; filter: drop-shadow(0 0 3px rgba(255, 230, 150, 0.8)); }
@keyframes twinkle { 0%, 100% { opacity: 0.15; transform: translate(-50%, -50%) scale(0.6) rotate(0deg); } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(20deg); } }
#fx { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.screen { position: fixed; inset: 0; z-index: 1; }

/* ───── 메뉴 ───── */
#menu { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l)); }
.menu-wrap { max-width: 980px; margin: 0 auto; display: grid; gap: 14px; justify-items: center; text-align: center; }
.menu-head { display: grid; justify-items: center; gap: 2px; }
.menu-head h1 { position: relative; margin: 2px 0 0; font-size: clamp(32px, 6.6vw, 58px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.t-main { font-weight: 800; color: #f3e6bf; letter-spacing: -0.035em; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
/* 「퍼즐」: 그림 하늘색 꼬리표, 살짝 기울여 손으로 붙인 스티커처럼 */
.t-ver { position: absolute; left: calc(100% + 0.3em); top: 2.9em; font-size: 12px; font-weight: 600; letter-spacing: 0; color: rgba(201, 220, 255, 0.55); white-space: nowrap; }
.t-tag { position: absolute; left: calc(100% + 0.16em); top: 0.12em; white-space: nowrap; padding: 0.12em 0.42em 0.16em; border-radius: 0.5em; font-size: 0.36em; font-weight: 800; letter-spacing: 0.04em; color: #0a1538;
  background: linear-gradient(180deg, #cfe8ff, var(--sky)); transform: rotate(-6deg); }
/* 「by 이름」: 그림 귀퉁이 서명처럼 — 기울인 세리프 + 양옆 가는 선 */
.byline { margin: 4px 0 0; display: flex; align-items: center; gap: 12px; color: #c9dcff; font: italic 400 clamp(16px, 2.4vw, 20px) / 1.2 Georgia, "Times New Roman", serif; letter-spacing: 0.06em; }
.byline::before, .byline::after { content: ""; width: clamp(28px, 8vw, 60px); height: 1px; background: linear-gradient(90deg, transparent, rgba(201, 220, 255, 0.7)); }
.byline::after { transform: scaleX(-1); }
.byline span { color: var(--star-soft); font-size: 1.12em; }
.menu-art { position: relative; display: block; width: min(560px, 88vw); aspect-ratio: 3 / 2; padding: 0; border: 0; background: none; cursor: zoom-in; animation: float 6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(-0.6deg); } }
.menu-art .art-badge { position: absolute; right: 6%; bottom: 4%; padding: 6px 12px; border-radius: 99px; font-size: 13.5px; font-weight: 800; color: #0a1538;
  background: rgba(243, 230, 191, 0.92); opacity: 0.85; transition: opacity 0.15s; }
.menu-art:hover .art-badge, .menu-art:focus-visible .art-badge { opacity: 1; }
.look-line { display: flex; align-items: center; gap: 10px; max-width: 100%; min-height: 44px; padding: 8px 8px 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(16, 30, 78, 0.75); font-size: 15px; }
.look-line #lookText { color: var(--ink); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.look-line .look-k { flex: 0 0 auto; color: var(--ink-dim); font-size: 13.5px; }
.look-line .look-go { flex: 0 0 auto; padding: 4px 12px; color: var(--sky); font-weight: 700; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.look-line.custom { border-color: rgba(255, 210, 63, 0.6); }
.menu-art canvas { width: 100%; height: 100%; filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.5)); }
.resume { display: flex; gap: 10px; align-items: center; justify-content: center; min-height: 52px; padding: 10px 24px; border: 0; border-radius: 999px;
  background: #f2c94c; color: #2a1a00; font-weight: 800; font-size: 18px; }
.resume small { font-weight: 600; opacity: 0.8; font-size: 14px; }
.levels-title { margin: 6px 0 0; font-size: 17px; color: var(--ink-dim); font-weight: 700; }
.levels { width: 100%; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.loading { grid-column: 1 / -1; color: var(--ink-dim); }
.level { position: relative; display: grid; gap: 4px; justify-items: center; padding: 14px 8px 12px; border-radius: 18px; border: 1px solid var(--line);
  background: rgba(17, 31, 82, 0.86); transition: border-color 0.12s; }
.level:hover { border-color: rgba(243, 230, 191, 0.6); }
.level:active { transform: scale(0.97); }
.level .lv-emo { font-size: 30px; line-height: 1.1; }
.level .lv-ic { font-size: 12px; letter-spacing: 1px; color: #f2c94c; line-height: 1; }
.level .lv-ic i { font-style: normal; color: rgba(255, 255, 255, 0.16); }
.level .lv-name { font-size: 19px; font-weight: 800; }
.level .lv-pcs { font-size: 14px; color: var(--sky); font-weight: 700; }
.level .lv-meta { font-size: 12.5px; color: var(--ink-dim); }
.level .lv-best { font-size: 13px; color: var(--star); min-height: 1.3em; }
.level .lv-best.none { color: var(--ink-dim); opacity: 0.7; }
.level .lv-tag { position: absolute; top: -9px; right: 8px; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: #13245c; border: 1px solid var(--line); color: var(--ink-dim); }
.menu-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip { border: 1px solid var(--line); background: rgba(16, 30, 78, 0.7); border-radius: 999px; padding: 10px 16px; min-height: 44px; font-size: 15px; }
.chip[aria-pressed="false"] { opacity: 0.7; }
/* 랜덤 카드: 한 줄 전체 */
.level.random { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 12px 14px; text-align: left; }
.level.random:hover { border-color: var(--line); }
.rnd-txt { display: grid; gap: 2px; margin-right: auto; }
.rnd-btns { display: flex; gap: 8px; }
.rnd-btn { display: grid; gap: 1px; justify-items: center; min-width: 92px; min-height: 52px; padding: 6px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); }
.rnd-btn:hover { border-color: rgba(243, 230, 191, 0.6); }
.rnd-btn b { font-size: 16px; }
.rnd-btn span { font-size: 12px; color: var(--ink-dim); }
.rnd-btn .lv-best { color: #f2c94c; }
@media (max-width: 760px) {
  .levels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .level:nth-child(5) { grid-column: 1 / -1; }
  .level.random { flex-wrap: wrap; }
  .rnd-btns { width: 100%; }
  .rnd-btn { flex: 1 1 0; min-width: 0; }
}

/* ───── 게임 화면 ───── */
#game { display: flex; flex-direction: column; }
.toolbar { position: relative; z-index: 5; flex: 0 0 auto; display: flex; align-items: center; gap: 6px; height: calc(var(--tb-h) + var(--safe-t));
  padding: var(--safe-t) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l)); background: rgba(6, 12, 40, 0.82); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); white-space: nowrap; }
.tools { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.tb { position: relative; display: inline-flex; align-items: center; gap: 5px; height: 40px; min-width: 40px; padding: 0 11px; border-radius: 12px;
  border: 1px solid transparent; background: rgba(255, 255, 255, 0.06); font-size: 15px; font-weight: 700; flex: 0 0 auto; }
.tb:hover { background: rgba(255, 255, 255, 0.13); }
.tb:active { transform: scale(0.95); }
.tb[aria-pressed="true"] { background: rgba(243, 230, 191, 0.18); border-color: rgba(243, 230, 191, 0.55); }
.tb .ic, .vw-bar .ic { width: 20px; height: 20px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic .fill { fill: currentColor; stroke: none; }
#btnSound .mute, #btnSound.off .on { display: none; }
#btnSound.off .mute { display: inline; }
.tb.chance { background: rgba(242, 201, 76, 0.16); border-color: rgba(242, 201, 76, 0.45); }
.tb.chance.empty { opacity: 0.45; }
.tb .badge { min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--star); color: #2a1a00; font-size: 12px; line-height: 20px; text-align: center; }
.tb.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
.status { display: flex; align-items: baseline; gap: 10px; min-width: 0; font-variant-numeric: tabular-nums; }
.st-level { font-weight: 800; color: var(--star-soft); overflow: hidden; text-overflow: ellipsis; }
.st-count { font-size: 15px; color: var(--ink-dim); }
.st-count b { color: var(--ink); font-size: 18px; }
.st-time { font-size: 15px; color: var(--sky); }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: rgba(255, 255, 255, 0.06); }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--sky), var(--star)); transition: width 0.3s; }
/* 좁은 화면: 도구 글씨 감추고 아이콘만(툴바는 한 줄 유지) */
@media (max-width: 820px) { .tb .lb { display: none; } .tb { padding: 0 9px; } }
@media (max-width: 480px) { .st-level { display: none; } .tb { min-width: 36px; height: 38px; padding: 0 6px; gap: 3px; } .tb .ic { font-size: 17px; } .tools { gap: 2px; } .toolbar { gap: 4px; padding-left: calc(4px + var(--safe-l)); padding-right: calc(4px + var(--safe-r)); } .status { gap: 6px; } .tb .badge { min-width: 18px; height: 18px; line-height: 18px; } }
@media (max-width: 360px) { #btnHelp { display: none; } }

#table { position: relative; flex: 1 1 auto; overflow: hidden; touch-action: none; }
#board { position: absolute; left: 0; top: 0; pointer-events: none; transition: filter 0.6s;
  filter: drop-shadow(0 0 1.5px rgba(170, 205, 255, 0.85)) drop-shadow(0 0 16px rgba(90, 140, 255, 0.35)); }
#hint { position: absolute; left: 0; top: 0; pointer-events: none; }
#pieces { position: absolute; inset: 0; }
.pc { position: absolute; left: 0; top: 0; will-change: transform; pointer-events: none; }
.pc.lift { filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.55)); }
.pc.sel { filter: drop-shadow(0 0 6px rgba(255, 220, 90, 0.95)) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5)); }
.pc.glide { transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
.pc.snapping { transition: transform 0.1s ease-out; }
.pc.pop { animation: pop 0.32s ease-out; }
@keyframes pop { 40% { filter: brightness(1.45); } }
.pc.flying { filter: drop-shadow(0 0 10px rgba(255, 230, 120, 1)) drop-shadow(0 8px 12px rgba(0, 0, 0, 0.5)); }
#table.done .pc { transition: opacity 0.8s; opacity: 0; }
#table.done #board { filter: drop-shadow(0 0 24px rgba(255, 225, 150, 0.45)); }

#toast { position: fixed; left: 50%; top: calc(var(--tb-h) + var(--safe-t) + 14px); z-index: 30; transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: rgba(10, 20, 60, 0.94); border: 1px solid var(--line); color: var(--ink); padding: 10px 18px; border-radius: 12px;
  font-weight: 700; font-size: 15.5px; transition: opacity 0.2s, transform 0.2s; white-space: nowrap; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───── 모달(완성·확인) ───── */
.modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; background: rgba(2, 6, 22, 0.55); animation: fade 0.25s; }
@keyframes fade { from { opacity: 0; } }
.card { width: min(440px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 22px 20px 18px;
  text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); animation: rise 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes rise { from { transform: translateY(30px) scale(0.9); opacity: 0; } }
.card h2 { margin: 4px 0 6px; font-size: 26px; font-weight: 800; color: #f3e6bf; }
.card p { margin: 6px 0; color: var(--ink-dim); line-height: 1.5; }
.res-stars { display: flex; justify-content: center; gap: 6px; font-size: 52px; line-height: 1; }
.res-stars span { color: rgba(255, 255, 255, 0.16); transform: scale(0.4); transition: transform 0.35s cubic-bezier(0.2, 1.8, 0.4, 1), color 0.2s; }
.res-stars span.on { color: #f2c94c; transform: scale(1); }
.res-stars span.off { transform: scale(0.8); }
.res-stats { list-style: none; margin: 12px 0 6px; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.res-stats li { background: rgba(255, 255, 255, 0.06); border-radius: 14px; padding: 8px 4px; display: grid; gap: 2px; }
.res-stats span { font-size: 12.5px; color: var(--ink-dim); }
.res-stats b { font-size: 19px; font-variant-numeric: tabular-nums; }
.res-record { color: #f2c94c !important; font-weight: 700; font-size: 16px; }
.res-tip { font-size: 13.5px; }
.res-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.btn { min-height: 46px; padding: 10px 16px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); font-weight: 800; font-size: 16px; }
.btn:hover { background: rgba(255, 255, 255, 0.15); }
.btn.primary { background: #f2c94c; color: #2a1a00; border: 0; }
.btn.ghost { background: transparent; }
.confirm p { color: var(--ink); font-size: 17px; font-weight: 700; }

/* ───── 플로팅 창 ───── */
.fwin { position: fixed; z-index: 50; display: flex; flex-direction: column; min-width: 220px; min-height: 160px; background: rgba(12, 24, 66, 0.96);
  border: 1px solid rgba(160, 190, 255, 0.35); border-radius: 14px; box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55); overflow: hidden; }
.fwin-bar { flex: 0 0 auto; display: flex; align-items: center; height: 40px; padding: 0 4px 0 12px; background: rgba(255, 255, 255, 0.07); cursor: move; touch-action: none; }
.fwin-title { flex: 1; font-size: 15px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fwin-close { width: 34px; height: 30px; border: 0; border-radius: 9px; background: var(--danger); color: #fff; font-size: 15px; font-weight: 900; line-height: 1; }
.fwin-close:hover { filter: brightness(1.15); }
.fwin-body { flex: 1 1 auto; min-height: 0; position: relative; }
.fwin-body.art canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.fwin-body.text { overflow-y: auto; padding: 10px 16px 14px; font-size: 15px; line-height: 1.6; -webkit-user-select: text; user-select: text; }
.fwin-resize { position: absolute; right: 0; bottom: 0; width: 26px; height: 26px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.35) 50%, rgba(255, 255, 255, 0.35) 58%, transparent 58%, transparent 70%, rgba(255, 255, 255, 0.35) 70%, rgba(255, 255, 255, 0.35) 78%, transparent 78%); }
.howto { padding-left: 1.3em; margin: 4px 0; }
.howto li { margin: 6px 0; }
.keys { color: var(--ink-dim); font-size: 13.5px; margin: 8px 0 0; }
kbd { display: inline-block; min-width: 1.6em; padding: 0 5px; border-radius: 5px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); text-align: center; font-family: inherit; font-size: 12.5px; }
.records { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.records th, .records td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: center; }
.records th { color: var(--ink-dim); font-size: 13px; font-weight: 700; }
.records td.stars { color: var(--star); letter-spacing: 1px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; z-index: 99; background: var(--night-0); }
/* ───── 그림 감상 ───── */
#viewer { z-index: 40; display: flex; flex-direction: column; background: radial-gradient(ellipse at 50% 40%, #16245a 0%, #0a1230 55%, #050a1e 100%); }
.vw-head { flex: 0 0 auto; display: flex; align-items: center; gap: 14px; padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) 8px calc(16px + var(--safe-l)); }
.vw-back { flex: 0 0 auto; height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid rgba(201, 220, 255, 0.35); background: rgba(255, 255, 255, 0.04); font-size: 15px; font-weight: 700; }
.vw-back:hover { background: rgba(255, 255, 255, 0.1); }
.vw-titles { min-width: 0; }
#vwTitle { margin: 2px 0 0; font: 400 clamp(22px, 3.4vw, 38px) / 1.15 "AppleMyungjo", "Nanum Myeongjo", "NanumMyeongjo", "Batang", "Noto Serif KR", Georgia, serif; letter-spacing: -0.01em; color: #f4f1e8; }
.vw-sub { margin: 4px 0 0; font-size: 13.5px; color: #aebbe0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vw-views { margin-left: auto; flex: 0 0 auto; display: flex; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(201, 220, 255, 0.2); }
.vw-views button { height: 36px; padding: 0 14px; border: 0; border-radius: 9px; background: none; font-size: 14.5px; font-weight: 700; color: var(--ink-dim); }
.vw-views button[aria-selected="true"] { background: #f4f1e8; color: #13204f; }
#vwStage { position: relative; flex: 1 1 auto; overflow: hidden; touch-action: none; cursor: zoom-in; }
#vwStage.zoomed { cursor: grab; }
#vwStage.grabbing { cursor: grabbing; }
#vwCanvas { position: absolute; inset: 0; }
#vwMini { position: absolute; right: 14px; bottom: 76px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.35); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); background: rgba(5, 10, 30, 0.7); cursor: pointer; touch-action: none; }
#vwHint { position: absolute; left: 50%; top: 14px; transform: translate(-50%, -6px); opacity: 0; pointer-events: none; padding: 8px 16px; border-radius: 99px;
  background: rgba(5, 10, 30, 0.82); border: 1px solid rgba(201, 220, 255, 0.3); font-size: 14px; font-weight: 700; white-space: nowrap; transition: opacity 0.25s, transform 0.25s; }
#vwHint.show { opacity: 1; transform: translate(-50%, 0); }
.vw-bar { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); z-index: 2; display: flex; gap: 6px; align-items: center; padding: 6px;
  border-radius: 16px; background: rgba(8, 14, 40, 0.86); border: 1px solid rgba(201, 220, 255, 0.25); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.vw-bar button, .vw-bar a { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 42px; padding: 0 10px; border-radius: 11px; border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06); color: var(--ink); font-size: 18px; font-weight: 700; text-decoration: none; font-variant-numeric: tabular-nums; }
.vw-bar #vwPct { min-width: 72px; font-size: 15px; }
.vw-bar #vwPctIn { width: 72px; height: 42px; border-radius: 11px; border: 1px solid #f3e6bf; background: #0a1230; color: var(--ink); font: 700 15px var(--font); text-align: center; -webkit-user-select: text; user-select: text; }
.vw-bar .wide { gap: 6px; font-size: 15px; padding: 0 14px; }
.vw-bar button:hover, .vw-bar a:hover { background: rgba(255, 255, 255, 0.14); }
.vw-bar button:disabled { opacity: 0.35; }
@media (max-width: 560px) {
  .vw-head { gap: 10px; padding-top: calc(6px + var(--safe-t)); }
  .vw-sub { font-size: 12px; }
  .vw-views button { padding: 0 10px; font-size: 13.5px; }
  .vw-back .lb, .vw-bar .lb { display: none; }
  .vw-bar .wide { padding: 0 10px; }
  #vwMini { bottom: 70px; right: 10px; }
}

/* ───── 퍼즐 꾸미기 창 ───── */
/* 꾸미기 창: 그림은 고정, 선택지만 스크롤. 창이 넓으면(760px 이상) 그림 | 선택지 두 단으로 펼침 */
#winStudio { container: studio / inline-size; }
.fwin-body.studio { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; background: #0c1842; }
.st-preview { position: relative; margin: 12px 14px 4px; height: clamp(110px, 24vh, 230px); border-radius: 12px; background: radial-gradient(ellipse at 50% 40%, #1b2f78, #0a1538); }
.st-groups { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 14px 10px; }
@container studio (min-width: 760px) {
  .fwin-body.studio { grid-template-columns: minmax(260px, 44%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .st-preview { grid-column: 1; grid-row: 1 / 3; height: auto; margin: 14px 4px 14px 14px; }
  .st-groups { grid-column: 2; grid-row: 1; padding-top: 10px; }
  .st-actions { grid-column: 2; grid-row: 2; }
}
.st-preview canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.st-busy { position: absolute; right: 10px; bottom: 8px; font-size: 12.5px; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: rgba(5, 10, 30, 0.8); }
.st-group h3 { margin: 4px 0 6px; font-size: 14px; color: var(--ink-dim); }
.st-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.st-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 4px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 14px; font-weight: 700; }
.st-chip .sw { margin-left: -8px; width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25); display: grid; place-items: center; font-size: 15px; background: rgba(255, 255, 255, 0.08); }
.st-chip[aria-checked="true"] { border-color: #f3e6bf; background: #f3e6bf; color: #13204f; }
/* 결정 버튼은 창 아래에 늘 보이게 */
.st-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 10px 14px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: #0c1842; }
@media (max-width: 480px) { .st-preview { height: clamp(96px, 18vh, 160px); } .st-chip { min-height: 36px; font-size: 13.5px; padding-right: 10px; } .st-actions .btn { flex: 1 1 auto; padding: 8px 10px; font-size: 15px; } }

/* ───── 판 확대(카메라) ───── */
#world { position: absolute; inset: 0; transform-origin: 0 0; }

/* ───── 사용자 칩 ───── */
.user-chip { position: absolute; left: calc(12px + var(--safe-l)); top: calc(12px + var(--safe-t)); z-index: 3; display: inline-flex; align-items: center; gap: 6px; max-width: 46vw;
  min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(16, 30, 78, 0.8); font-size: 14.5px; }
.user-chip b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu { position: fixed; }
@media (max-width: 560px) { .menu-wrap { padding-top: 40px; } }

/* ───── 툴바: 좁은 화면은 「더보기」에 모음 ───── */
.narrowonly { display: none !important; }
@media (max-width: 600px) { .narrowonly { display: inline-flex !important; } .wideonly { display: none !important; } }
.more-menu { position: absolute; right: calc(8px + var(--safe-r)); top: calc(100% + 6px); z-index: 20; display: grid; min-width: 180px; padding: 6px; border-radius: 14px;
  background: rgba(12, 24, 66, 0.98); border: 1px solid var(--line); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); }
.more-menu button { text-align: left; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: none; font-size: 15px; font-weight: 700; }
.more-menu button:hover { background: rgba(255, 255, 255, 0.08); }

/* ───── 공통 입력·작은 단추 ───── */
.text-in { width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: #0a1230; color: var(--ink); font: 600 16px var(--font); -webkit-user-select: text; user-select: text; }
.text-in:focus { outline: 2px solid #f3e6bf; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: 13.5px; border-radius: 10px; }
.res-rank { color: #f3e6bf !important; font-weight: 700; }
.muted-line { color: var(--ink-dim); font-size: 13.5px; margin: 6px 0; }
.empty { list-style: none; color: var(--ink-dim); padding: 10px 2px; }
#userModal .card input { margin: 10px 0 2px; }

/* 사용자 목록 */
.user-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.user-row { display: flex; gap: 6px; align-items: center; }
.user-row .u-pick { flex: 1; min-height: 44px; text-align: left; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-size: 15px; }
.user-row.on .u-pick { border-color: #f3e6bf; background: rgba(243, 230, 191, 0.14); }
.user-row .text-in { flex: 1; }
.user-add { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.user-add .text-in { flex: 1; min-width: 0; height: 44px; }
.user-add .btn { flex: none; white-space: nowrap; min-height: 44px; }

/* 하던 퍼즐 · 갤러리 카드 */
.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.save-card { display: grid; grid-template-columns: 88px 1fr; gap: 10px; align-items: center; padding: 8px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); }
.save-card img, .save-card .noimg { width: 88px; height: 60px; object-fit: contain; border-radius: 8px; background: #0d1838; }
.sc-info { display: grid; gap: 3px; min-width: 0; font-size: 13px; color: var(--ink-dim); }
.sc-info b { color: var(--ink); font-size: 15px; }
.sc-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-info .bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.sc-info .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--sky), var(--star)); }
.sc-acts { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.gal-grid { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.gal-card { display: grid; gap: 4px; padding: 8px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-size: 13px; color: var(--ink-dim); }
.gal-card b { color: var(--ink); font-size: 13.5px; }
.gal-card .g-img { padding: 0; border: 0; background: #0d1838; border-radius: 10px; cursor: zoom-in; }
.gal-card .g-img img { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: contain; }
.gal-card .sc-acts { justify-content: flex-start; flex-wrap: nowrap; }
.gal-card .sc-acts [data-a=use] { flex: 1; }

/* 순위·기록 */
.tabs { display: flex; gap: 4px; margin-bottom: 10px; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
.tabs button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: none; font-weight: 700; color: var(--ink-dim); }
.tabs button[aria-selected="true"] { background: #f3e6bf; color: #13204f; }
.sc-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.sc-filters select { flex: 1 1 120px; min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #0a1230; color: var(--ink); font: 600 14px var(--font); padding: 0 8px; }
.sc-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.sc-row { display: grid; grid-template-columns: 34px 1fr auto auto auto; gap: 8px; align-items: center; min-height: 44px; padding: 4px 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); font-variant-numeric: tabular-nums; }
.sc-row.me { outline: 1px solid #f3e6bf; background: rgba(243, 230, 191, 0.1); }
.sc-row .rk { text-align: center; font-weight: 800; }
.sc-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.sc-row .tm { font-weight: 800; }
.sc-row .st { color: #f2c94c; font-size: 12px; }
@media (max-width: 480px) { .sc-row { grid-template-columns: 28px 1fr auto auto; } .sc-row .st { display: none; } }

@media (prefers-reduced-motion: reduce) { #twinkles i, .menu-art, #table.done #board, .res-record { animation: none; } }
