:root {
  --font: 'Zen Maru Gothic', system-ui, sans-serif;
  --ink: #fdf7ee;
  --sub: rgba(253, 247, 238, .72);
  --glass: rgba(24, 22, 38, .55);
  --glass-strong: rgba(20, 18, 32, .82);
  --line: rgba(255, 255, 255, .16);
  --accent: #f3c25b;
  --accent-ink: #2a1d05;
  --radius: 16px;
  --bubble-bg: rgba(255, 252, 245, .94);
  --bubble-ink: #3a3045;
}
body.scene-inn {
  --font: 'DotGothic16', monospace;
  --glass: rgba(10, 12, 40, .78);
  --glass-strong: rgba(10, 12, 40, .92);
  --line: #e9e4ff;
  --accent: #ffd34d;
  --radius: 2px;
  --bubble-bg: #0c0e2c;
  --bubble-ink: #fff;
}
body.scene-showa90 {
  --font: 'M PLUS Rounded 1c', system-ui, sans-serif;
  --glass: rgba(60, 24, 40, .55);
  --glass-strong: rgba(48, 20, 36, .86);
  --accent: #ff8a5b;
  --accent-ink: #2a0d05;
  --radius: 10px;
  --bubble-bg: #fff6e4;
  --bubble-ink: #4a2230;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0b16; color: var(--ink); font-family: var(--font); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--glass); border-radius: calc(var(--radius) * .7); padding: .45em .9em; backdrop-filter: blur(8px); }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
[hidden] { display: none !important; }

/* ---------- 舞台（3:2 の絵を画面いっぱいに） ---------- */
#stage {
  position: fixed; left: 50%; top: 50%;
  width: max(100vw, 150vh); height: max(100vh, 66.667vw);
  transform: translate(-50%, -50%);
  animation: breathe 9s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: translate(-50%, -50%) scale(1.012); } }
.layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: opacity 1.4s ease; pointer-events: none; }
#imgBlink { transition: none; }
#puppet { display: none; }
body[data-puppet] #puppet { display: block; }
body[data-puppet] #imgWork, body[data-puppet] #imgBreak, body[data-puppet] #imgBlink { visibility: hidden; }
body.scene-inn .layer { image-rendering: pixelated; }
#glow { mix-blend-mode: screen; }
body.scene-tokyo #glow { background: radial-gradient(circle at 19% 37%, rgba(255, 196, 120, .35), transparent 22%); animation: lamp 6s ease-in-out infinite; }
body.scene-inn #glow { background: radial-gradient(circle at 13% 52%, rgba(255, 140, 40, .45), transparent 20%), radial-gradient(circle at 31% 60%, rgba(255, 200, 90, .35), transparent 7%); animation: fire 0.9s steps(3) infinite; }
body.scene-showa90 #glow { background: radial-gradient(circle at 16% 32%, rgba(255, 190, 110, .3), transparent 20%); animation: lamp 7s ease-in-out infinite; }
@keyframes lamp { 50% { opacity: .55; } }
@keyframes fire { 0% { opacity: 1; } 33% { opacity: .7; } 66% { opacity: .9; } }
#grain { opacity: 0; }
body.scene-showa90 #grain {
  opacity: .16; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain .5s steps(4) infinite;
}
@keyframes grain { 25% { transform: translate(-2%, 1%); } 50% { transform: translate(1%, -2%); } 75% { transform: translate(2%, 2%); } }

/* ---------- 吹き出し ---------- */
#bubble {
  position: fixed; z-index: 4;
  max-width: min(28vw, 360px); padding: .9em 1.1em;
  background: var(--bubble-bg); color: var(--bubble-ink);
  border-radius: 18px 18px 18px 4px; font-size: clamp(14px, 1.15vw, 18px); line-height: 1.7;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  animation: pop .35s ease-out;
}
#bubble::before { content: 'ミオ'; display: block; font-size: .72em; font-weight: 700; opacity: .55; margin-bottom: .2em; }
body.scene-inn #bubble { border: 4px double #fff; border-radius: 0; box-shadow: none; }
body.scene-inn #bubble::before { content: 'ミオ ▼'; opacity: .8; }
body.scene-showa90 #bubble { border: 3px solid #4a2230; box-shadow: 5px 5px 0 #4a2230; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- 上の帯 ---------- */
#top { position: fixed; top: 16px; left: 16px; right: 16px; display: flex; align-items: center; gap: 14px; z-index: 5; }
.brand { font-weight: 700; letter-spacing: .08em; padding: .35em .8em; background: var(--glass); border-radius: var(--radius); backdrop-filter: blur(8px); }
.level { display: flex; align-items: center; gap: 8px; padding: .35em .8em; background: var(--glass); border-radius: var(--radius); backdrop-filter: blur(8px); font-size: 14px; }
.bar { width: 110px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .6s; }
.pt { color: var(--sub); }
.tools { margin-left: auto; display: flex; gap: 8px; }
.tools b { background: var(--accent); color: var(--accent-ink); border-radius: 9px; padding: 0 .45em; font-size: .8em; }
.tools b:empty { display: none; }

/* ---------- タイマー ---------- */
#dock {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 5;
  background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--line);
  border-radius: calc(var(--radius) * 1.3); padding: 14px 22px 16px; text-align: center; min-width: 300px;
}
.modes { display: flex; gap: 6px; justify-content: center; }
.modes button { font-size: 12px; padding: .25em .7em; }
.modes button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
#clock { font-size: 56px; font-weight: 700; letter-spacing: .04em; line-height: 1.1; margin-top: 6px; font-variant-numeric: tabular-nums; }
#status { font-size: 13px; color: var(--sub); margin: 2px 0 10px; }
.row { display: flex; gap: 8px; justify-content: center; }

/* ---------- 話しかける ---------- */
#chat { position: fixed; right: 16px; bottom: 22px; z-index: 5; display: flex; gap: 6px; flex-wrap: wrap; width: min(380px, calc(100vw - 32px)); }
#chat input { flex: 1; min-width: 0; padding: .6em .9em; border-radius: calc(var(--radius) * .7); border: 1px solid var(--line); background: var(--glass-strong); }
#chat input::placeholder { color: var(--sub); }
#aiState { width: 100%; font-size: 11px; color: var(--sub); text-align: right; }

/* ---------- パネル ---------- */
.panel {
  position: fixed; top: 70px; right: 16px; bottom: 90px; width: min(360px, calc(100vw - 32px)); z-index: 6;
  background: var(--glass-strong); backdrop-filter: blur(12px); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; overflow: auto;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.panel h2.sub { margin-top: 22px; }
.hint { font-size: 12px; color: var(--sub); line-height: 1.6; }
#taskForm { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
#taskForm input { padding: .5em .7em; border-radius: 8px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); }
#taskForm #taskTitle { grid-column: 1 / -1; }
#taskList { list-style: none; padding: 0; margin: 14px 0; }
#taskList li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
#taskList li.done .t { text-decoration: line-through; opacity: .5; }
#taskList .t { flex: 1; line-height: 1.4; }
#taskList .due { font-size: 12px; color: var(--sub); white-space: nowrap; }
#taskList .due.hot { color: #ff9b8a; font-weight: 700; }
#taskList button { padding: .1em .5em; }
#taskList .del { border: none; background: none; opacity: .4; }

.mix { display: grid; grid-template-columns: 5.5em 1fr; align-items: center; gap: 8px; margin: 10px 0; }
.mix input { width: 100%; accent-color: var(--accent); }

#sceneList, #outfitList { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { position: relative; padding: 0; overflow: hidden; border-radius: calc(var(--radius) * .7); text-align: left; }
.card img { display: block; width: 100%; aspect-ratio: 3/2; object-fit: cover; }
.card span { display: block; padding: 6px 8px; font-size: 12px; }
.card.on { outline: 2px solid var(--accent); }
.card.locked img { filter: grayscale(1) brightness(.35) blur(2px); }
.card.locked::after { content: attr(data-lock); position: absolute; inset: 0 0 28px; display: grid; place-items: center; font-size: 13px; }

#toast { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); z-index: 9; background: var(--accent); color: var(--accent-ink); padding: .7em 1.3em; border-radius: 999px; font-weight: 700; animation: pop .4s ease-out; }

#gate { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(8, 6, 16, .55); backdrop-filter: blur(3px); }
.gateBox { text-align: center; }
.gateTitle { font-size: 44px; font-weight: 700; letter-spacing: .12em; }
.gateBox p { color: var(--sub); line-height: 1.8; }
#gate .credit { font-size: 11px; margin: -6px 0 18px; }
#dl { margin-top: 22px; font-size: 13px; }
#dl a { color: var(--accent); }

/* ミニ表示：絵とタイマーだけ */
body.mini #top .level, body.mini #chat, body.mini .panel, body.mini .modes, body.mini #status { display: none !important; }
body.mini #dock { padding: 8px 16px; min-width: 0; }
body.mini #clock { font-size: 32px; margin: 0; }

@media (max-width: 760px) {
  .brand, .level .pt { display: none; }
  .tools button { padding: .4em .6em; font-size: 13px; }
  #bubble { left: 16px !important; right: 16px; top: 70px !important; max-width: none; }
  #dock { bottom: 84px; min-width: 0; width: calc(100vw - 32px); }
  #clock { font-size: 44px; }
  #chat { left: 16px; right: 16px; bottom: 16px; width: auto; }
}
