:root {
  --bg: #1d1a3a; --panel: #fbf8ff; --panel2: #eee8fb; --line: rgba(74, 59, 143, 0.18);
  --text: #2e2850; --dim: #7a7299; --accent: #7c4dff; --accent2: #ffb300; --ok: #43a047; --bad: #e53935;
  --card: rgba(255, 255, 255, 0.08); --cardline: rgba(255, 255, 255, 0.16); --ink: #f3efff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% -10%, #3b3170 0%, #1d1a3a 55%, #120f26 100%) fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex; flex-direction: column; overflow: hidden; height: 100dvh;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 0.82rem; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; flex: none;
  background: rgba(56, 189, 248, 0.14); border: 1px solid rgba(56, 189, 248, 0.35); color: #7dd3fc;
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(56, 189, 248, 0.24); }
.hud { display: flex; gap: 5px; margin-left: auto; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 5px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--card); border: 1px solid var(--cardline); font-size: 0.84rem;
}
.chip.lv { flex-direction: column; gap: 2px; padding: 3px 10px; align-items: stretch; }
.chip.lv span { line-height: 1.1; font-size: 0.8rem; text-align: center; }
.bar { display: block; width: 50px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent2); border-radius: 3px; transition: width 0.3s; }
.tools { display: flex; gap: 6px; flex: none; }
.mini { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--cardline); background: var(--card); color: inherit; font-weight: 800; }

/* ── 섬 ── */
.island { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 16px; position: relative; -webkit-overflow-scrolling: touch; }
.sec { max-width: 980px; margin: 0 auto 10px; }
.sec h2 { display: flex; align-items: center; gap: 8px; margin: 6px 2px 8px; font-size: 1rem; }
.sec h2 small { font-weight: 600; font-size: 0.76rem; color: #b7aedd; }
.sec h2 .btn { margin-left: auto; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.slot {
  flex: none; width: 150px; min-height: 150px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--cardline); text-align: center; position: relative;
}
.slot.ready { border-color: #ffd740; box-shadow: 0 0 0 2px rgba(255, 215, 64, 0.35), 0 0 18px rgba(255, 215, 64, 0.25); }
.slot.empty { justify-content: center; color: #b7aedd; font-size: 0.82rem; border-style: dashed; }
.slot.add { justify-content: center; border-style: dashed; color: #b7aedd; font-size: 0.8rem; }
.slot canvas { width: 70px; height: 70px; }
.slot.cave { width: 220px; }
.slot.cave .pair { display: flex; align-items: center; gap: 2px; }
.slot.cave .pair canvas { width: 64px; height: 56px; }
.slot b { font-size: 0.86rem; }
.slot .t { font-size: 0.78rem; color: #d6ceff; font-variant-numeric: tabular-nums; }
.slot .acts { display: flex; gap: 4px; margin-top: auto; flex-wrap: wrap; justify-content: center; }
.pbar { width: 100%; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.14); overflow: hidden; }
.pbar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7c4dff, #ffb300); }
.new { position: absolute; top: 6px; right: 6px; font-size: 0.66rem; font-weight: 800; padding: 1px 6px; border-radius: 999px; background: #ff4081; color: #fff; }

.plots { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.plot { border-radius: 16px; background: var(--card); border: 1px solid var(--cardline); overflow: hidden; display: flex; flex-direction: column; min-height: 168px; }
.plot .ph { display: flex; align-items: center; gap: 6px; padding: 7px 10px; font-size: 0.86rem; font-weight: 700; white-space: nowrap; min-width: 0; }
.plot .ph small { overflow: hidden; text-overflow: ellipsis; }
.plot .ph small { color: #b7aedd; font-weight: 600; font-size: 0.72rem; }
.plot .ph .mini { margin-left: auto; width: 28px; height: 28px; font-size: 0.85rem; }
.plot .scene { position: relative; }
.plot canvas.hab { display: block; width: 100%; height: 118px; touch-action: manipulation; cursor: pointer; }
.coinbtn {
  position: absolute; right: 8px; top: 8px; padding: 4px 9px; border-radius: 999px; border: 0; font-weight: 800; font-size: 0.8rem;
  background: #ffca28; color: #4e342e; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.coinbtn.full { animation: bob 0.9s ease-in-out infinite; background: #ffb300; }
@keyframes bob { 50% { transform: translateY(-3px); } }
.plot .pf { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px 8px; }
.dchip { padding: 3px 8px; border-radius: 999px; border: 1px solid var(--cardline); background: rgba(255,255,255,0.06); font-size: 0.74rem; }
.dchip.adult { border-color: rgba(255, 215, 64, 0.5); }
.plot.empty, .plot.lock { align-items: center; justify-content: center; border-style: dashed; color: #b7aedd; gap: 6px; padding: 12px; text-align: center; font-size: 0.86rem; cursor: pointer; }
.plot.empty .big, .plot.lock .big { font-size: 1.8rem; }
.plot.lock { opacity: 0.85; }
.plot.farm .farmbody { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 10px;
  background: repeating-linear-gradient(0deg, #6d4c41 0 10px, #5d4037 10px 20px); }
.plot.farm .crop { font-size: 2.4rem; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3)); }
.plot.farm .crop.grow { animation: sway 2s ease-in-out infinite; }
@keyframes sway { 50% { transform: rotate(6deg); } }
.plot.farm .t { font-size: 0.8rem; color: #fff3e0; font-variant-numeric: tabular-nums; }
.plot.farm .pbar { width: 80%; }

.toasts { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(92%, 420px); z-index: 25; }
.toast {
  padding: 8px 14px; border-radius: 14px; background: rgba(29, 26, 58, 0.94); border: 1px solid var(--cardline); color: var(--ink); font-size: 0.86rem; font-weight: 600;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); animation: tin 0.25s ease-out; text-align: center;
}
.toast.gold { background: linear-gradient(135deg, #ffb300, #ff7043); color: #fff; border: 0; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }
.floaty { position: fixed; pointer-events: none; font-weight: 900; color: #ffd740; text-shadow: 0 2px 4px rgba(0,0,0,0.6); animation: fly 0.9s ease-out forwards; z-index: 26; }
@keyframes fly { to { transform: translateY(-36px); opacity: 0; } }

.dock { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 6px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: rgba(18, 15, 38, 0.6); }
.dbtn {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; border-radius: 14px;
  border: 1px solid var(--cardline); background: var(--card); font-size: 1.25rem;
}
.dbtn span { font-size: 0.72rem; font-weight: 700; }
.dot { position: absolute; top: 5px; right: calc(50% - 20px); width: 9px; height: 9px; border-radius: 50%; background: #ff4081; box-shadow: 0 0 0 2px var(--bg); }

/* ── 버튼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 9px 14px; border-radius: 12px; border: 0;
  background: var(--accent); color: #fff; font-weight: 800; text-decoration: none; white-space: nowrap;
}
.btn.small { padding: 6px 10px; font-size: 0.8rem; }
.btn.ghost { background: var(--panel2); color: var(--text); }
.island .btn.ghost, .slot .btn.ghost, .plot .btn.ghost { background: rgba(255,255,255,0.12); color: var(--ink); }
.btn.ok { background: var(--ok); }
.btn.gold { background: #ffb300; color: #3e2723; }
.btn.bad { background: var(--bad); }

/* ── 아래 서랍 ── */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  width: min(100%, 620px); max-height: 86dvh; display: flex; flex-direction: column; background: var(--panel); color: var(--text); border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom); animation: up 0.22s ease-out; box-shadow: 0 -8px 30px rgba(0,0,0,0.4);
}
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } }
.sheet-head { flex: none; display: flex; align-items: center; padding: 12px 14px 6px 18px; font-size: 1.05rem; }
.sheet-head b { flex: 1; }
.sheet-head .mini, .mcard .mini { color: var(--text); border-color: var(--line); background: var(--panel2); }
.sheet-tabs { flex: none; display: flex; gap: 6px; padding: 0 14px 8px; overflow-x: auto; scrollbar-width: none; }
.sheet-tabs:empty { display: none; }
.stab { flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); font-weight: 700; font-size: 0.84rem; }
.stab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sheet-body { overflow-y: auto; padding: 4px 14px 18px; -webkit-overflow-scrolling: touch; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 3px; padding: 9px; border-radius: 14px; text-align: left;
  border: 1px solid var(--line); background: #fff; color: var(--text);
}
.card.locked { opacity: 0.55; }
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.card.busy { opacity: 0.5; }
.card canvas { width: 100%; height: 70px; border-radius: 10px; background: linear-gradient(#f3efff, #e6defc); }
.card b { font-size: 0.88rem; }
.card small { color: var(--dim); font-size: 0.73rem; line-height: 1.35; }
.card .price { margin-top: auto; font-weight: 800; font-size: 0.84rem; }
.card .price.no { color: var(--bad); }
.tierdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: #fff; margin-bottom: 8px;
}
.row .ico { font-size: 1.6rem; flex: none; width: 36px; text-align: center; }
.row .txt { flex: 1; min-width: 0; }
.row .txt b { display: block; font-size: 0.92rem; }
.row .txt small { color: var(--dim); font-size: 0.78rem; }
.note { padding: 10px 12px; border-radius: 12px; background: var(--panel2); font-size: 0.84rem; margin-bottom: 10px; line-height: 1.5; }
.prog { height: 7px; border-radius: 4px; background: var(--panel2); overflow: hidden; margin-top: 4px; }
.prog > i { display: block; height: 100%; background: var(--ok); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-bottom: 12px; }
.stat { padding: 8px 10px; border-radius: 12px; background: var(--panel2); }
.stat b { display: block; font-size: 1.1rem; }
.stat small { color: var(--dim); font-size: 0.74rem; }
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.ach div { padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 0.8rem; }
.ach div.no { opacity: 0.45; filter: grayscale(1); }
.ach b { display: block; font-size: 0.86rem; }
h3.sec2 { margin: 12px 0 8px; font-size: 0.95rem; }

/* 교배 */
.pairbox { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 4px 0 10px; }
.pick {
  width: 120px; height: 110px; border-radius: 16px; border: 2px dashed var(--line); background: var(--panel2); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 0.8rem; color: var(--dim); padding: 4px;
}
.pick.on { border-color: var(--accent); border-style: solid; background: #fff; }
.pick canvas { width: 96px; height: 70px; }
.heart { font-size: 1.6rem; }
.odds { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin: 8px 0; }
.odd { padding: 6px; border-radius: 12px; background: #fff; border: 1px solid var(--line); text-align: center; font-size: 0.74rem; }
.odd canvas { width: 100%; height: 48px; }
.odd b { display: block; font-size: 0.8rem; }
.odd .pct { font-weight: 800; color: var(--accent); }
.daytime { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--panel2); font-weight: 700; font-size: 0.78rem; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,0.55); display: grid; place-items: center; padding: 16px; }
.mcard {
  width: min(100%, 420px); max-height: 88dvh; overflow-y: auto; background: var(--panel); color: var(--text); border-radius: 20px; padding: 18px; text-align: center;
  animation: pop 0.25s ease-out; box-shadow: 0 16px 40px rgba(0,0,0,0.45);
}
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.mcard h2 { margin: 6px 0 8px; font-size: 1.2rem; }
.mcard p { margin: 6px 0; font-size: 0.9rem; line-height: 1.5; }
.mcard .big { font-size: 2.6rem; }
.mcard canvas.hero { width: 180px; height: 150px; }
.mcard ul { text-align: left; padding-left: 20px; margin: 8px 0; font-size: 0.86rem; line-height: 1.6; }
.mcard .acts { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.mcard .list { text-align: left; margin-top: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; text-align: left; font-size: 0.86rem; margin: 10px auto; max-width: 300px; }
.kv span:nth-child(odd) { color: var(--dim); }
.tierlbl { display: inline-block; padding: 2px 9px; border-radius: 999px; color: #fff; font-size: 0.74rem; font-weight: 800; }

.err { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #120f26; padding: 16px; }
.err-card { background: var(--panel); color: var(--text); border-radius: 20px; padding: 22px; text-align: center; max-width: 380px; }
.err-ico { font-size: 3rem; }
.err-card .btn { margin: 4px; }
.noscript { color: #fff; text-align: center; }

@media (max-width: 520px) {
  .back-txt { display: none; }
  .back-btn { padding: 7px 9px; }
  .chip { padding: 4px 7px; font-size: 0.76rem; }
  .bar { width: 36px; }
  .plots { grid-template-columns: 1fr 1fr; gap: 6px; }
  .plot canvas.hab { height: 96px; }
  .plot .ph { padding: 6px 8px; font-size: 0.78rem; }
  .slot { width: 128px; }
  .slot.cave { width: 196px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 430px) {
  .tools #helpBtn { display: none; }
}
@media (max-width: 380px) {
  .hud { gap: 3px; }
  .chip { padding: 3px 6px; }
}
button.row { font: inherit; color: inherit; text-align: left; }
button.row:disabled { opacity: 0.5; }
button.card { font: inherit; }
