:root {
  --bg: #eaf6fb;
  --panel: #fffaf2;
  --paper: #fffdf8;
  --ink: #23303a;
  --muted: #74838f;
  --line: #e6dccb;
  --chip: rgba(255, 255, 255, 0.82);
  --accent: #ff8a3d;
  --accent2: #ff5f6d;
  --ok: #3cbf74;
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1b24; --panel: #18242d; --ink: #e9f1f5; --muted: #93a3ad; --line: #2b3a45; --chip: rgba(20, 32, 40, 0.78);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1b24; --panel: #18242d; --ink: #e9f1f5; --muted: #93a3ad; --line: #2b3a45; --chip: rgba(20, 32, 40, 0.78);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
[hidden] { display: none !important; }

#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(320px, 56dvh);
  grid-template-columns: minmax(0, 1fr);
}
#app > section { min-width: 0; min-height: 0; }
@media (orientation: landscape) and (min-width: 700px) {
  #app { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr) clamp(384px, 34vw, 460px); }
}

/* ---------- 鱼缸 ---------- */
#tankWrap { position: relative; overflow: hidden; background: #1677b3; }
#tank { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hud { position: absolute; left: 0; right: 0; display: flex; gap: 8px; padding: 10px 12px; pointer-events: none; }
.hud.top { top: env(safe-area-inset-top); }
.hud.bottom { bottom: 0; }
.hud > * { pointer-events: auto; }
.spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 36px; padding: 0 14px;
  border-radius: 18px; background: var(--chip); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 15px; font-weight: 600; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.chip:active { transform: scale(0.96); }
.caret { opacity: 0.6; font-size: 12px; }
#missionBadge { color: var(--ok); }
.pill { padding: 4px 10px; border-radius: 12px; background: rgba(0, 0, 0, 0.22); color: #fff; font-size: 13px; font-weight: 600; pointer-events: none; }
.hint {
  position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 20px; background: rgba(255, 255, 255, 0.9); color: #23303a;
  font-size: 14px; font-weight: 600; white-space: nowrap; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); transition: opacity 0.5s, transform 0.5s;
  animation: bob 2.4s ease-in-out infinite;
}
.hint.gone { opacity: 0; transform: translate(-50%, 10px); animation: none; }
@keyframes bob { 50% { transform: translate(-50%, -4px); } }

/* ---------- 画板 ---------- */
#padWrap {
  display: flex; flex-direction: column; gap: 8px; min-height: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.08);
}
@media (orientation: landscape) and (min-width: 700px) {
  #padWrap { border-top: 0; border-left: 1px solid var(--line); padding-top: calc(10px + env(safe-area-inset-top)); }
}
.toolbar { display: flex; align-items: center; gap: 6px; min-width: 0; }
.colors { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 5px; margin: -3px; }
.colors::-webkit-scrollbar, .types::-webkit-scrollbar { display: none; }
.swatch {
  flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); transition: transform 0.15s;
}
.swatch.on { transform: scale(1.12); box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink); }
.seg { display: flex; background: rgba(127, 127, 127, 0.12); border-radius: 12px; padding: 2px; }
.tool, .seg button { height: 34px; min-width: 36px; padding: 0 6px; border-radius: 10px; font-size: 17px; display: grid; place-items: center; }
.tool.soft { background: rgba(127, 127, 127, 0.12); }
.seg button.on { background: var(--paper); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); color: #23303a; }
.sizes i { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: currentColor; }
.sizes button.on i { background: #23303a; }

.padBox {
  position: relative; flex: 1; min-height: 120px; border-radius: var(--radius); overflow: hidden;
  background-color: var(--paper);
  background-image: radial-gradient(circle, rgba(35, 48, 58, 0.09) 1.2px, transparent 1.3px);
  background-size: 22px 22px;
  box-shadow: inset 0 0 0 1px var(--line), 0 2px 8px rgba(0, 0, 0, 0.05);
}
#pad { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.guide {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 4px;
  color: #9aa6ae; font-size: 15px; pointer-events: none;
}
.guide b { color: #6c7a84; }
.g-emoji { font-size: 34px; opacity: 0.6; }
.g-sub { font-size: 13px; opacity: 0.85; }

.sendRow { display: flex; align-items: center; gap: 8px; min-width: 0; }
.types { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.type {
  flex: none; display: flex; align-items: center; gap: 4px; height: 38px; padding: 0 12px;
  border-radius: 19px; background: rgba(127, 127, 127, 0.12); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.type .e { font-size: 17px; }
.type.on { background: #23303a; color: #fff; }
.type.locked { opacity: 0.45; }
.send {
  flex: none; height: 46px; padding: 0 18px; border-radius: 23px; font-size: 16px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 6px 16px rgba(255, 110, 70, 0.35); transition: transform 0.15s, opacity 0.2s;
}
.send:not(:disabled):active { transform: scale(0.95); }
.send:disabled { opacity: 0.45; box-shadow: none; }

#fly { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 20; }

/* ---------- 弹窗 ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; justify-items: center; }
.backdrop { position: absolute; inset: 0; background: rgba(10, 25, 35, 0.4); animation: fade 0.2s; }
.panel {
  position: relative; width: min(640px, 100%); max-height: 82dvh; display: flex; flex-direction: column;
  background: var(--panel); border-radius: 22px 22px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
  padding-bottom: env(safe-area-inset-bottom); animation: up 0.25s cubic-bezier(.2, .9, .3, 1.1);
}
@media (min-width: 700px) { .sheet { align-items: center; } .panel { border-radius: 22px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.panel header { display: flex; align-items: center; padding: 14px 16px 6px; }
.panel h2 { flex: 1; margin: 0; font-size: 19px; }
.x { width: 34px; height: 34px; border-radius: 50%; background: rgba(127, 127, 127, 0.15); font-size: 15px; }
.body { overflow-y: auto; padding: 8px 16px 18px; user-select: text; -webkit-user-select: text; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.center { text-align: center; padding: 30px 0; }

.tank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tank-card {
  position: relative; height: 104px; border-radius: 16px; padding: 10px; text-align: left; color: #fff;
  display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden;
  background: linear-gradient(180deg, var(--a), var(--b) 78%, var(--s) 78%);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.tank-card.on { box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--accent); }
.tank-card.locked { filter: grayscale(0.8) brightness(0.8); }
.tc-emoji { position: absolute; top: 8px; right: 10px; font-size: 24px; }
.tc-name { font-weight: 800; font-size: 16px; }
.tc-count { font-size: 12px; opacity: 0.95; }

.missions { display: flex; flex-direction: column; gap: 8px; }
.mission { padding: 10px 12px; border-radius: 14px; background: rgba(127, 127, 127, 0.09); }
.mission.ok { background: rgba(60, 191, 116, 0.12); }
.m-top { display: flex; justify-content: space-between; font-weight: 700; font-size: 15px; }
.m-prog { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: rgba(127, 127, 127, 0.18); margin: 7px 0 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 3px; }
.mission.ok .bar i { background: var(--ok); }
.m-reward { font-size: 12.5px; color: var(--muted); }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.cat-card { padding: 6px; border-radius: 14px; background: rgba(127, 127, 127, 0.09); text-align: center; min-width: 0; }
.cat-img { aspect-ratio: 1; display: grid; place-items: center; border-radius: 10px; background: var(--paper); padding: 6px; }
.cat-img img { max-width: 100%; max-height: 100%; }
.cat-name { font-size: 13px; font-weight: 700; margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-sub { font-size: 11.5px; color: var(--muted); }
.link { color: var(--accent); font-weight: 700; padding: 4px 0 10px; }
.detail-img { display: grid; place-items: center; height: 160px; border-radius: 16px; background: var(--paper); padding: 12px; margin-bottom: 12px; }
.detail-img img { max-width: 100%; max-height: 100%; }
.field { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; width: 100%; resize: none;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .field :is(input, select, textarea) { background: #22313b; } }
:root[data-theme="dark"] .field :is(input, select, textarea) { background: #22313b; }
.actions { display: flex; gap: 10px; margin-top: 6px; }
.btn { flex: 1; height: 44px; border-radius: 14px; font-weight: 700; background: rgba(127, 127, 127, 0.14); }
.btn.primary { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.btn.danger { flex: 0 0 auto; padding: 0 18px; color: #e5484d; }

#toasts { position: fixed; top: calc(56px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast {
  max-width: 100%; padding: 10px 16px; border-radius: 14px; background: rgba(35, 48, 58, 0.92); color: #fff;
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  opacity: 0; transform: translateY(-10px) scale(0.97); transition: opacity 0.3s, transform 0.3s;
}
.toast.in { opacity: 1; transform: none; }
.toast.gold { background: linear-gradient(135deg, #ffb53d, #ff7a45); }

/* ---------- 新增 ---------- */
.chip.icon { padding: 0; width: 38px; justify-content: center; font-size: 17px; }
.chip.small { height: 32px; width: 32px; font-size: 15px; }
.hud.bottom { align-items: center; }

.padBtn {
  position: absolute; height: 32px; min-width: 32px; padding: 0 8px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.92); color: #23303a; font-size: 14px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.padBtn.left { top: 8px; left: 8px; }
.padBtns { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
.padBtns .padBtn { position: static; }

.gameBar {
  position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 6px; border-radius: 18px;
  background: rgba(255, 255, 255, 0.94); color: #23303a; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); max-width: calc(100% - 24px);
}
.gameBar img { width: 52px; height: 40px; object-fit: contain; border-radius: 10px; background: #f3f6f8; }
.gameBar img[src=""] { display: none; }
.gb-text { display: flex; flex-direction: column; min-width: 0; }
.gb-text b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gb-text span { font-size: 12px; color: #74838f; }
.gameBar.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(calc(-50% - 8px)); } 40%, 80% { transform: translateX(calc(-50% + 8px)); } }

.recBadge { position: absolute; top: calc(56px + env(safe-area-inset-top)); right: 12px; padding: 6px 12px; border-radius: 14px; background: rgba(229, 72, 77, 0.92); color: #fff; font-weight: 700; font-size: 14px; }

.catchCard { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; background: rgba(10, 25, 35, 0.45); animation: fade 0.2s; }
.cc-inner { width: min(320px, calc(100% - 40px)); padding: 18px; border-radius: 24px; background: var(--panel); text-align: center; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25); animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.cc-title { font-size: 20px; font-weight: 800; margin-bottom: 10px; }
.cc-img { height: 170px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(#bfeaff, #6fc4ef); margin-bottom: 14px; padding: 10px; }
.cc-img img { max-width: 100%; max-height: 100%; animation: wobble 1.2s ease-in-out infinite; }
@keyframes wobble { 50% { transform: rotate(-6deg) scale(1.05); } }

/* 观赏模式：只留场景 */
.exitShow { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
body.show #padWrap, body.show .hud, body.show #hint { display: none !important; }
body.show #app { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
body.show.awake .exitShow { opacity: 1; pointer-events: auto; }
body.show.night #tankWrap::after { content: ""; position: absolute; inset: 0; background: rgba(5, 10, 30, 0.5); pointer-events: none; }
.qrBox {
  position: absolute; right: 16px; bottom: 16px; padding: 10px 10px 8px; border-radius: 16px; background: rgba(255, 255, 255, 0.95);
  text-align: center; color: #23303a; font-size: 13px; font-weight: 700; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}
.qrBox img { display: block; width: 132px; height: 132px; image-rendering: pixelated; margin-bottom: 4px; }

/* 菜单与列表 */
.menu { display: grid; gap: 8px; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: rgba(127, 127, 127, 0.09); text-align: left; }
.menu-item .mi-icon { font-size: 24px; width: 32px; text-align: center; }
.menu-item .mi-text { display: flex; flex-direction: column; }
.menu-item b { font-size: 15px; }
.menu-item span span, .menu-item .mi-sub { font-size: 12.5px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 800; color: var(--muted); margin: 14px 2px 8px; }
.section-title:first-child { margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { height: 36px; padding: 0 14px; border-radius: 18px; background: rgba(127, 127, 127, 0.12); font-weight: 700; font-size: 14px; }
.chip-btn.on { background: #23303a; color: #fff; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.tpl-card { padding: 6px; border-radius: 14px; background: rgba(127, 127, 127, 0.09); font-size: 13px; font-weight: 700; }
.tpl-card canvas { width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; background: #fff; display: block; margin-bottom: 4px; }
.share-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.share-row input { flex: 1; min-width: 0; font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.qr-big { display: grid; place-items: center; margin: 6px 0 4px; }
.qr-big img { width: 180px; height: 180px; image-rendering: pixelated; border-radius: 12px; background: #fff; padding: 6px; }
.room-list { display: grid; gap: 6px; }
.room-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 12px; background: rgba(127, 127, 127, 0.09); }
.room-item img { width: 44px; height: 34px; object-fit: contain; }
.room-item .ri-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item .ri-by { font-size: 12px; color: var(--muted); }
.stat-row { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin: 0 0 10px; align-items: center; }
.grow { flex: 1; height: 6px; border-radius: 3px; background: rgba(127, 127, 127, 0.18); overflow: hidden; }
.grow i { display: block; height: 100%; background: var(--ok); }
.voice-row { display: flex; gap: 8px; margin-bottom: 10px; }
.voice-row .btn { flex: 1; }
.btn.rec { background: #e5484d; color: #fff; }
video.preview { width: 100%; border-radius: 14px; background: #000; margin-bottom: 10px; }
.world-tag { font-size: 11px; padding: 1px 6px; border-radius: 8px; background: rgba(127, 127, 127, 0.15); }
.flash { position: fixed; inset: 0; background: #fff; z-index: 50; pointer-events: none; animation: flash 0.4s forwards; }
@keyframes flash { to { opacity: 0; } }

/* ---------- 辅助画画 ---------- */
#trace { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.padBtns.bottom-left { top: auto; bottom: 8px; left: 8px; right: auto; }
.padBtns.bottom-right { top: auto; bottom: 8px; right: 8px; }
.padBtn.toggle { opacity: 0.75; }
.padBtn.toggle.on { opacity: 1; background: #23303a; color: #fff; }
.padBtn:disabled { opacity: 0.35; }
.guide.compact { place-content: start center; padding: 14px 120px 0; }
.guide.compact .g-sub { font-size: 12.5px; }
.guide.compact .g-emoji { display: none; }
.tool { position: relative; }
.caret-dot { position: absolute; right: 3px; bottom: 4px; width: 0; height: 0; border-left: 3px solid transparent; border-right: 3px solid transparent; border-top: 4px solid currentColor; opacity: 0.5; }
.stickers .stk { flex: none; width: 38px; height: 34px; border-radius: 10px; background: rgba(127, 127, 127, 0.1); display: grid; place-items: center; }
.stickers .stk.on { background: var(--paper); box-shadow: 0 0 0 2px var(--ink); }
.stickers .stk canvas { width: 30px; height: 30px; }
.brush-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.brush-card { padding: 8px; border-radius: 14px; background: rgba(127, 127, 127, 0.09); font-weight: 700; font-size: 14px; }
.brush-card.on { box-shadow: 0 0 0 2px var(--ink); }
.brush-card canvas { width: 100%; height: 44px; display: block; background: #fff; border-radius: 10px; margin-bottom: 4px; }

/* ---------- 手机竖屏：给画板更多空间 ---------- */
@media (orientation: portrait) and (max-width: 600px) {
  #padWrap { gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .padBtn .lbl { display: none; }
  .padBtn { min-width: 30px; height: 30px; padding: 0 6px; }
  .padBtn.left, .padBtns { top: 6px; }
  .padBtn.left { left: 6px; }
  .padBtns { right: 6px; }
  .padBtns.bottom-left { bottom: 6px; left: 6px; }
  .padBtns.bottom-right { bottom: 6px; right: 6px; }
  .guide.compact { padding: 10px 104px 0; }
}
/* 很窄的手机（320 宽）：工具按钮缩小 */
@media (max-width: 360px) {
  .toolbar { gap: 4px; }
  .tool, .seg button { min-width: 30px; padding: 0 3px; font-size: 15px; }
  .swatch { width: 26px; height: 26px; }
  .send { padding: 0 12px; font-size: 15px; }
}
