:root {
  --bg: #0a0c16;
  --bg2: #10142a;
  --panel: #151b30;
  --panel2: #1d2440;
  --text: #eef2ff;
  --muted: #8b93b0;
  --cyan: #4ff0ff;
  --violet: #9b6bff;
  --pink: #ff4fd8;
  --gold: #ffd54f;
  --red: #ff3b5c;
  --green: #4fe3a0;
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

.app {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; width: 100%; max-width: 560px; margin: 0 auto; background: var(--bg);
  padding-top: var(--safe-top);
}

/* HUD */
.hud {
  display: grid; grid-template-columns: 1fr auto 44px; align-items: center; gap: 8px;
  padding: 6px 10px 4px 12px; min-height: 54px; background: linear-gradient(180deg, #0e1226, #0a0c16);
  border-bottom: 1px solid #1f2745;
}
.hud-form-name { font-weight: 800; font-size: 15px; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-form-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-mass { text-align: right; }
.hud-mass-value { font-weight: 900; font-size: 22px; line-height: 1.05; font-variant-numeric: tabular-nums; color: #fff; text-shadow: 0 0 12px rgba(79, 240, 255, 0.35); white-space: nowrap; }
.hud-mass-value.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 0% { transform: scale(1.18); color: var(--cyan); } 100% { transform: scale(1); } }
.hud-mass-sub { font-size: 11px; color: var(--muted); display: flex; gap: 10px; justify-content: flex-end; }
.hud-cores { color: var(--gold); font-weight: 700; }
.hud-menu {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid #2a3358; background: #161c33; font-size: 20px; line-height: 1;
}
.hud-menu:active { background: #232c4d; }

/* Field */
.field-wrap { position: relative; flex: 1 1 auto; min-height: 220px; overflow: hidden; background: #000; }
.field { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: 92%;
  padding: 8px 14px; border-radius: 999px; background: rgba(10, 12, 22, 0.82); border: 1px solid rgba(79, 240, 255, 0.5);
  font-size: 13px; font-weight: 700; color: #fff; white-space: nowrap; pointer-events: none; animation: hintIn 0.3s ease-out;
  box-shadow: 0 0 18px rgba(79, 240, 255, 0.25);
}
@keyframes hintIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); padding: 8px 14px; border-radius: 12px;
  background: rgba(21, 27, 48, 0.94); border: 1px solid #2a3358; font-size: 13px; font-weight: 700; pointer-events: none; white-space: nowrap;
  animation: hintIn 0.25s ease-out;
}
.toast.warn { border-color: var(--red); color: #ffd6dd; box-shadow: 0 0 16px rgba(255, 59, 92, 0.35); }
.toast.good { border-color: var(--green); }
.float-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

/* Controls */
.controls {
  flex: 0 0 auto; padding: 8px 10px calc(10px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(180deg, #0c0f1f, #090b14); border-top: 1px solid #1f2745;
}
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chip {
  position: relative; min-height: 56px; border-radius: 14px; border: 1px solid #2a3358; background: #141a2f; padding: 6px 4px 5px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; text-align: center; overflow: hidden;
  transition: transform 0.08s ease, border-color 0.2s ease, background 0.2s ease;
}
.chip:active { transform: scale(0.96); }
.chip-name { font-size: 12px; font-weight: 800; letter-spacing: 0.02em; }
.chip-lv { font-size: 10px; color: var(--muted); }
.chip-cost { font-size: 11px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.can { border-color: var(--cyan); background: #12253a; box-shadow: inset 0 0 0 1px rgba(79, 240, 255, 0.25), 0 0 12px rgba(79, 240, 255, 0.15); }
.chip.can .chip-cost { color: var(--cyan); }
.chip.max .chip-cost { color: var(--gold); }
.chip.urgent { border-color: var(--red); animation: urgentPulse 1s ease-in-out infinite; }
@keyframes urgentPulse { 0%, 100% { box-shadow: 0 0 0 rgba(255, 59, 92, 0); } 50% { box-shadow: 0 0 14px rgba(255, 59, 92, 0.55); } }
.chip.bought { animation: chipPop 0.3s ease-out; }
@keyframes chipPop { 0% { transform: scale(1.08); background: #1f3f5a; } 100% { transform: scale(1); } }

.evolve-row { display: flex; gap: 6px; align-items: stretch; }
.evolve {
  position: relative; flex: 1 1 auto; height: 40px; border-radius: 12px; border: 1px solid #2a3358; background: #141a2f; overflow: hidden;
  font-weight: 800; font-size: 14px; letter-spacing: 0.03em;
}
.evolve-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: linear-gradient(90deg, #4b3aa8, #7b5cff); transition: width 0.35s ease; opacity: 0.85; }
.evolve-label { position: relative; z-index: 1; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.evolve.ready { border-color: var(--violet); animation: evolveGlow 1.4s ease-in-out infinite; }
.evolve.ready .evolve-fill { background: linear-gradient(90deg, #7b5cff, #ff4fd8); }
@keyframes evolveGlow { 0%, 100% { box-shadow: 0 0 6px rgba(155, 107, 255, 0.3); } 50% { box-shadow: 0 0 20px rgba(255, 79, 216, 0.7); } }
.evolve.final { border-color: var(--gold); }
.evolve.final .evolve-fill { background: linear-gradient(90deg, #b8860b, #ffd54f); }

.od-btn {
  flex: 0 0 auto; width: 74px; height: 40px; border-radius: 12px; border: 1px solid var(--gold); background: #2a2210; color: var(--gold);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; gap: 2px; font-weight: 900;
  animation: odGlow 1.2s ease-in-out infinite;
}
.od-btn .od-title { font-size: 12px; }
.od-btn .od-state { font-size: 10px; }
.od-btn.held { animation: none; background: #1a1a1a; border-color: #6b5a2a; color: #b9a45a; }
@keyframes odGlow { 0%, 100% { box-shadow: 0 0 4px rgba(255, 213, 79, 0.3); } 50% { box-shadow: 0 0 18px rgba(255, 213, 79, 0.8); } }

.suck {
  position: relative; width: 100%; min-height: 92px; border-radius: 24px; border: 2px solid #3e7cff; overflow: hidden;
  background: linear-gradient(180deg, #2b6cff, #1a3db5); box-shadow: 0 8px 0 #0f2470, 0 12px 24px rgba(43, 108, 255, 0.35);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.2s ease;
}
.suck:active, .suck.pressed { transform: translateY(6px); box-shadow: 0 2px 0 #0f2470, 0 4px 10px rgba(43, 108, 255, 0.3); }
.suck:disabled { filter: saturate(0.5) brightness(0.75); }
.suck-gauge {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%; transition: width 0.4s ease;
  background: repeating-linear-gradient(135deg, rgba(255, 179, 0, 0.95) 0 10px, rgba(255, 213, 79, 0.95) 10px 20px);
  box-shadow: inset -3px 0 6px rgba(0, 0, 0, 0.25);
}
.suck-gauge::after { content: '限界ゲージ'; position: absolute; left: 8px; top: 5px; font-size: 9px; font-weight: 900; color: rgba(60, 30, 0, 0.75); letter-spacing: 0.05em; white-space: nowrap; }
.suck-inner { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px; }
.suck-label { font-size: 30px; font-weight: 900; letter-spacing: 0.08em; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); }
.suck-sub { font-size: 12px; font-weight: 700; color: rgba(255, 255, 255, 0.85); white-space: nowrap; }
.suck.ready { animation: suckBreath 1.6s ease-in-out infinite; }
@keyframes suckBreath { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.15); } }
.suck.od { border-color: var(--gold); background: linear-gradient(180deg, #ffb300, #ff6f00); box-shadow: 0 8px 0 #7a3b00, 0 12px 28px rgba(255, 179, 0, 0.5); }
.suck.od .suck-gauge { background: rgba(255, 255, 255, 0.15); }
.suck.od .suck-label { color: #fff8e1; }
.suck.od:active, .suck.od.pressed { box-shadow: 0 2px 0 #7a3b00, 0 4px 10px rgba(255, 179, 0, 0.4); }
.suck.empty { border-color: #34406a; background: linear-gradient(180deg, #2d3a6b, #1c2447); box-shadow: 0 8px 0 #0f1633; }

/* Stage card */
.stage-card {
  position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; z-index: 20;
  width: max-content; max-width: 86%;
  padding: 14px 20px; border-radius: 20px; background: rgba(10, 12, 22, 0.78); border: 1px solid rgba(155, 107, 255, 0.55);
  box-shadow: 0 0 40px rgba(155, 107, 255, 0.35); animation: cardIn 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes cardIn { from { opacity: 0; transform: translate(-50%, -50%) scale(0.6); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.stage-card.out { animation: cardOut 0.4s ease-in forwards; }
@keyframes cardOut { to { opacity: 0; transform: translate(-50%, -60%) scale(0.9); } }
.stage-card-kicker { font-size: 12px; letter-spacing: 0.3em; color: var(--violet); font-weight: 700; }
.stage-card-title { font-size: 24px; font-weight: 900; margin: 4px 0; text-shadow: 0 0 16px rgba(155, 107, 255, 0.6); white-space: nowrap; }
.stage-card-sub { font-size: 12px; color: var(--muted); line-height: 1.5; }
.controls.collapse, .hud.collapse { transition: transform 2.4s ease-in, opacity 2s ease-in; transform: scale(0.1); opacity: 0; transform-origin: 50% 0%; }

/* Overlays */
.overlay {
  position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(6, 8, 16, 0.86); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.panel {
  width: 100%; max-width: 420px; max-height: calc(100% - 8px); overflow: auto; border-radius: 22px; background: var(--panel); border: 1px solid #2a3358;
  padding: 18px 16px calc(14px + var(--safe-bottom)); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); -webkit-overflow-scrolling: touch;
}
.panel-tall { height: calc(100% - 8px); display: flex; flex-direction: column; }
.panel-kicker { font-size: 12px; letter-spacing: 0.35em; color: var(--red); font-weight: 800; text-align: center; }
.panel-title { font-size: 20px; font-weight: 900; margin: 6px 0 12px; text-align: center; line-height: 1.35; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; font-size: 13px; }
.stats-grid .k { color: var(--muted); }
.stats-grid .v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.cores-earned { text-align: center; font-size: 26px; font-weight: 900; color: var(--gold); margin: 14px 0 6px; text-shadow: 0 0 14px rgba(255, 213, 79, 0.5); }
.panel-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.btn {
  min-height: 48px; border-radius: 14px; border: 1px solid #2a3358; background: #1d2440; font-weight: 800; font-size: 15px; padding: 10px 16px;
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(180deg, #2b6cff, #1a3db5); border-color: #3e7cff; box-shadow: 0 4px 0 #0f2470; color: #fff; }
.btn-big { min-height: 60px; font-size: 20px; letter-spacing: 0.08em; }
.btn-secondary { background: #1d2440; }
.btn-danger { background: #3a1420; border-color: #7a2436; color: #ffd6dd; }
.btn:disabled { opacity: 0.45; }
.panel-close { margin-top: 10px; flex: 0 0 auto; }

/* Title */
.title { background: radial-gradient(ellipse at 50% 30%, #1a1f45 0%, #0a0c16 65%); }
.title-inner { text-align: center; max-width: 380px; width: 100%; position: relative; }
.title-vortex {
  width: 200px; height: 200px; margin: 0 auto 6px; border-radius: 50%;
  background: conic-gradient(from 0deg, #4ff0ff, #9b6bff, #ff4fd8, #ffd54f, #4ff0ff);
  -webkit-mask: radial-gradient(circle, transparent 28%, #000 30%, #000 45%, transparent 47%, #000 49%, #000 62%, transparent 64%, #000 66%, #000 78%, transparent 80%);
  mask: radial-gradient(circle, transparent 28%, #000 30%, #000 45%, transparent 47%, #000 49%, #000 62%, transparent 64%, #000 66%, #000 78%, transparent 80%);
  animation: spin 6s linear infinite; opacity: 0.9; filter: blur(0.4px) drop-shadow(0 0 20px rgba(155, 107, 255, 0.5));
}
@keyframes spin { to { transform: rotate(360deg); } }
.title-logo { margin: 0 0 12px; display: flex; flex-direction: column; gap: 4px; }
.title-logo-main { font-size: 42px; font-weight: 900; letter-spacing: 0.06em; background: linear-gradient(180deg, #fff, #9be9ff); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; filter: drop-shadow(0 0 16px rgba(79, 240, 255, 0.45)); }
.title-logo-sub { font-size: 14px; color: var(--muted); letter-spacing: 0.2em; font-weight: 700; }
.title-howto { text-align: left; margin: 0 auto 10px; padding: 0 0 0 26px; font-size: 14px; line-height: 1.7; max-width: 260px; }
.title-howto b { color: var(--cyan); }
.title-warn { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 0 0 16px; }
.title-warn b { color: var(--red); }
.title-save { font-size: 12px; color: var(--muted); margin-top: 10px; min-height: 16px; }
#startBtn { width: 100%; }

/* Ending */
.ending { background: #000; }
.ending-inner { text-align: center; max-width: 360px; }
.ending-text { font-size: 18px; line-height: 2; font-weight: 700; min-height: 120px; }
.ending-text .line { display: block; opacity: 0; animation: fadeIn 1.2s ease forwards; }
@keyframes fadeIn { to { opacity: 1; } }
.ending-text .line.big { font-size: 28px; font-weight: 900; color: var(--gold); }

/* Menu */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 10px; flex: 0 0 auto; }
.tab { min-height: 44px; border-radius: 12px; border: 1px solid #2a3358; background: #141a2f; font-weight: 800; font-size: 13px; }
.tab.active { background: #2b3a6b; border-color: #4f6cff; }
.tab-page { display: none; flex: 1 1 auto; overflow: auto; -webkit-overflow-scrolling: touch; }
.tab-page.active { display: block; }
.perm-header { display: flex; justify-content: space-between; align-items: center; font-weight: 800; margin-bottom: 8px; font-size: 14px; }
.cores { color: var(--gold); font-size: 18px; }
.perm-list { display: flex; flex-direction: column; gap: 8px; }
.perm {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 12px; border-radius: 14px;
  background: #11162a; border: 1px solid #2a3358;
}
.perm-name { font-weight: 800; font-size: 14px; }
.perm-desc { grid-column: 1; font-size: 11px; color: var(--muted); line-height: 1.4; }
.perm-buy { grid-row: 1 / span 2; min-width: 84px; min-height: 48px; border-radius: 12px; border: 1px solid #2a3358; background: #1d2440; font-weight: 800; font-size: 13px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.perm-buy small { font-size: 11px; color: var(--gold); }
.perm-buy.can { border-color: var(--gold); background: #2a2210; }
.perm-buy:disabled { opacity: 0.5; }
.note { font-size: 11px; color: var(--muted); line-height: 1.5; }
.dex-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.dex-stage { grid-column: 1 / -1; font-weight: 800; font-size: 12px; color: var(--violet); margin-top: 6px; letter-spacing: 0.1em; }
.dex { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; background: #11162a; border: 1px solid #222a48; font-size: 12px; }
.dex canvas { width: 32px; height: 32px; flex: 0 0 auto; }
.dex .dex-name { font-weight: 700; }
.dex .dex-sub { color: var(--muted); font-size: 10px; }
.dex.unseen { opacity: 0.45; }
.settings-list { display: flex; flex-direction: column; gap: 6px; }
.setting { display: flex; justify-content: space-between; align-items: center; min-height: 48px; padding: 0 12px; border-radius: 12px; background: #11162a; border: 1px solid #222a48; font-weight: 700; font-size: 14px; }
.setting input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--cyan); }
.setting select { font-size: 14px; padding: 6px 10px; border-radius: 8px; background: #1d2440; color: #fff; border: 1px solid #2a3358; }
.settings-actions { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.save-box { width: 100%; border-radius: 10px; background: #0b0e1c; color: #cfd6ff; border: 1px solid #2a3358; font-size: 11px; padding: 8px; resize: vertical; font-family: ui-monospace, monospace; }

/* Compact phones */
@media (max-height: 700px) {
  .chip { min-height: 50px; }
  .suck { min-height: 78px; }
  .suck-label { font-size: 26px; }
  .evolve { height: 36px; }
  .od-btn { height: 36px; }
  .hud { min-height: 48px; }
  .hud-mass-value { font-size: 19px; }
}
@media (max-height: 600px) {
  .suck { min-height: 68px; }
  .suck-sub { display: none; }
  .chip { min-height: 46px; }
  .chip-lv { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .title-vortex { animation: none; }
}
