:root {
  --bg: #0b0c10;
  --bg2: #14161c;
  --panel: #1a1d25;
  --border: #2c303a;
  --text: #e8e8ec;
  --muted: #9098a8;
  --accent: #ff4d4d;
  --accent2: #ffd24d;
  --ok: #4dff9e;
  --warn: #ffd24d;
  --danger: #ff4d4d;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.95rem;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #22252f; border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- タイトル画面 ---------- */
#title-screen {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 30%, #1c1116 0%, #0b0c10 70%);
  text-align: center;
  padding: 20px;
}
.scanline-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0px, rgba(255,255,255,0.025) 1px, transparent 1px, transparent 3px);
  mix-blend-mode: overlay;
}
.title-flicker {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(circle at 50% 40%, rgba(255,77,77,0.08), transparent 60%);
  animation: title-flicker 4s infinite;
}
@keyframes title-flicker {
  0%, 19%, 21%, 100% { opacity: 1; }
  20% { opacity: 0.6; }
  55% { opacity: 1; }
  56% { opacity: 0.75; }
  57% { opacity: 1; }
}
#title-screen h1 {
  font-size: 2.4rem;
  letter-spacing: 0.15em;
  margin: 0;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255,77,77,0.5);
}
#title-screen .subtitle {
  color: var(--muted);
  margin-top: -10px;
  max-width: 480px;
  line-height: 1.7;
}
.title-buttons { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
.title-buttons button { padding: 12px 24px; font-size: 1.05rem; }
#new-game-btn { border-color: var(--accent); }
#best-day-label { color: var(--accent2); font-size: 0.9rem; margin-top: -4px; }

/* ---------- ヘッダー ---------- */
#app { max-width: 1280px; margin: 0 auto; padding: 14px 16px 60px; display: none; }

header#top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
}
header#top-bar h1 {
  font-size: 1.1rem;
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.stat-block { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.stat-block .stat-label { font-size: 0.7rem; color: var(--muted); }
.stat-block .stat-value { font-size: 1.15rem; font-weight: bold; }

.bar-outline {
  width: 90px; height: 8px; background: #000; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill { height: 100%; transition: width 0.3s; }
.bar-ok { background: var(--ok); }
.bar-warn { background: var(--warn); }
.bar-danger { background: var(--danger); }

.header-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

#breach-alert {
  background: linear-gradient(90deg, #3a0a0a, #5a0f0f, #3a0a0a);
  border: 1px solid var(--danger);
  color: #ffdada;
  font-weight: bold;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  animation: breach-flash 1s infinite;
}
@keyframes breach-flash {
  0%, 100% { box-shadow: 0 0 6px rgba(255,77,77,0.3); }
  50% { box-shadow: 0 0 20px rgba(255,77,77,0.8); }
}

#quota-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 14px;
}
#quota-panel .panel-title { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
#quota-list { display: flex; gap: 18px; flex-wrap: wrap; }
.quota-item { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.quota-label { font-size: 0.85rem; width: 32px; }
.quota-bar { flex: 1; height: 8px; background: #000; border-radius: 4px; overflow: hidden; border: 1px solid var(--border); min-width: 60px; }
.quota-bar-fill { height: 100%; transition: width 0.3s; }
.quota-num { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* ---------- メインレイアウト ---------- */
main#layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
}
@media (max-width: 900px) {
  main#layout { grid-template-columns: 1fr; }
}

section.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.panel-header h2 { font-size: 0.95rem; margin: 0; color: var(--muted); letter-spacing: 0.05em; }

/* ---------- 施設フロア図(本家のエレベーター断面風レイアウト) ---------- */
#cells-grid {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.floor-row {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: repeating-linear-gradient(180deg, #101217, #101217 1px, #14161c 1px, #14161c 2px);
}
.floor-row:last-child { border-bottom: none; }
.floor-label {
  flex-shrink: 0;
  width: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #0c0d11;
  border-right: 1px solid var(--border);
  padding: 6px 2px;
}
.floor-num { font-weight: bold; color: var(--accent2); font-size: 0.9rem; letter-spacing: 0.03em; }
.floor-dept { font-size: 0.6rem; color: var(--muted); text-align: center; line-height: 1.2; }
.floor-content { flex: 1; padding: 8px; min-width: 0; }

.cell {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #12141a;
  cursor: pointer;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.1s, box-shadow 0.15s;
}
.cell:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.cell-empty { align-items: center; justify-content: center; cursor: default; opacity: 0.5; min-height: 60px; }
.cell-empty:hover { transform: none; box-shadow: none; }
.cell-empty-label { color: var(--muted); font-size: 0.85rem; }
.cell-breached {
  background: repeating-linear-gradient(135deg, #2a1010, #2a1010 8px, #1a0a0a 8px, #1a0a0a 16px);
  animation: pulse-danger 1.4s infinite;
}
@keyframes pulse-danger {
  0%, 100% { box-shadow: 0 0 0 rgba(255,77,77,0.0); }
  50% { box-shadow: 0 0 14px rgba(255,77,77,0.55); }
}
.cell-head { display: flex; justify-content: space-between; align-items: center; }
.tier-badge, .type-badge {
  font-size: 0.68rem; padding: 2px 6px; border-radius: 4px; border: 1px solid; font-weight: bold;
}
.cell-status { font-size: 0.72rem; color: var(--muted); }
.cell-breached .cell-status { color: var(--danger); font-weight: bold; }
.cell-name { font-size: 0.95rem; font-weight: bold; }
.cell-types { display: flex; gap: 4px; flex-wrap: wrap; }
.qliphoth-row { display: flex; align-items: center; gap: 6px; }
.qliphoth-label { font-size: 0.62rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.counter-pips { font-size: 0.9rem; letter-spacing: 2px; color: var(--accent2); }
.breach-progress { font-size: 0.78rem; color: var(--danger); font-weight: bold; }
.assigned-list { margin-top: auto; display: flex; flex-wrap: wrap; gap: 4px; }
.assigned-chip {
  font-size: 0.72rem; background: #23303a; color: #9adfff; padding: 2px 6px; border-radius: 10px;
}
.assigned-empty { font-size: 0.72rem; color: var(--muted); }

/* ---------- 職員 ---------- */
#roster-wrap { display: flex; flex-direction: column; gap: 8px; max-height: 560px; overflow-y: auto; }
.employee-card {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #12141a;
  cursor: pointer;
}
.employee-card:hover { border-color: #444a58; }
.employee-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.employee-busy { border-color: #4da3ff; }
.employee-dead { opacity: 0.4; cursor: default; }
.emp-name-row { display: flex; justify-content: space-between; align-items: center; }
.emp-name { font-weight: bold; font-size: 0.92rem; }
.emp-dead-badge { font-size: 0.68rem; color: var(--danger); border: 1px solid var(--danger); border-radius: 4px; padding: 1px 5px; }
.emp-dept { font-size: 0.66rem; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; white-space: nowrap; }
.emp-bars { display: flex; gap: 6px; margin: 5px 0; }
.mini-bar { position: relative; flex: 1; height: 14px; background: #000; border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.mini-bar-fill { height: 100%; transition: width 0.3s; }
.mini-bar-fill.hp { background: #ff5c5c; }
.mini-bar-fill.sp { background: #4da3ff; }
.mini-bar-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.62rem; color: #fff; text-shadow: 0 0 2px #000; }
.emp-stats { display: flex; gap: 6px; flex-wrap: wrap; font-size: 0.75rem; margin-bottom: 4px; }
.stat-chip { background: #00000055; padding: 1px 5px; border-radius: 4px; }
.stat-chip-combat { color: #c7d0dd; border: 1px solid #4a5568; }
.emp-quote { font-size: 0.72rem; color: var(--muted); font-style: italic; margin-bottom: 6px; }
.rest-btn { width: 100%; font-size: 0.78rem; padding: 4px; }

/* ---------- ログ ---------- */
#log-panel { margin-top: 14px; }
#log-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column-reverse; gap: 4px; font-size: 0.82rem; }
.log-entry { border-bottom: 1px dashed var(--border); padding-bottom: 3px; }
.log-tag { color: var(--muted); margin-right: 6px; font-size: 0.72rem; }

/* ---------- フッター操作 ---------- */
#action-bar {
  position: sticky; bottom: 0;
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 12px;
  margin-top: 16px;
  border-radius: 10px;
}
#next-phase-btn { border-color: var(--accent2); font-weight: bold; padding: 10px 26px; }

/* ---------- モーダル共通 ---------- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-box h2 { margin-top: 0; color: var(--accent); }
.modal-close-row { text-align: right; margin-top: 14px; }

.achv-item { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 6px; }
.achv-done { border-color: var(--accent2); }
.achv-locked { opacity: 0.5; }
.achv-name { font-weight: bold; font-size: 0.9rem; }
.achv-desc { font-size: 0.78rem; color: var(--muted); }

.changelog-entry { margin-bottom: 14px; }
.changelog-head { font-weight: bold; color: var(--accent2); }
.changelog-date { color: var(--muted); font-weight: normal; font-size: 0.8rem; margin-left: 6px; }
.changelog-changes { margin: 4px 0 0 18px; font-size: 0.85rem; }

.help-body p, .help-body li { line-height: 1.7; font-size: 0.9rem; }

/* ---------- 日次決算モーダル ---------- */
#dayreport-verdict { text-align: center; font-weight: bold; font-size: 1.1rem; margin: 6px 0 14px; padding: 8px; border-radius: 8px; }
.dayreport-verdict-ok { color: var(--ok); background: #10281c; border: 1px solid var(--ok); }
.dayreport-verdict-ng { color: var(--danger); background: #2a1010; border: 1px solid var(--danger); }
.dayreport-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; border-radius: 6px; margin-bottom: 6px; font-size: 0.9rem;
  border: 1px solid var(--border);
}
.dayreport-row.dr-met { border-color: var(--ok); }
.dayreport-row.dr-unmet { border-color: var(--danger); }
.dr-mark { font-weight: bold; }
.dr-met .dr-mark { color: var(--ok); }
.dr-unmet .dr-mark { color: var(--danger); }
.dayreport-summary { display: flex; justify-content: space-around; margin-top: 12px; font-size: 0.95rem; font-weight: bold; }
.dayreport-newabno { margin-top: 12px; text-align: center; color: var(--accent2); font-size: 0.85rem; border: 1px dashed var(--accent2); border-radius: 6px; padding: 6px; }

/* ---------- ゲームオーバー ---------- */
#gameover-modal .modal-box { text-align: center; }
#gameover-grade { font-size: 3rem; font-weight: bold; color: var(--accent2); margin: 8px 0; }
.gameover-stats { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin: 14px 0; }
.gameover-stat { display: flex; flex-direction: column; }
.gameover-stat .v { font-size: 1.3rem; font-weight: bold; }
.gameover-stat .l { font-size: 0.72rem; color: var(--muted); }

/* ---------- トースト ---------- */
#toast-wrap {
  position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200;
}
.toast {
  background: linear-gradient(135deg, #2a2210, #1a1610);
  border: 1px solid var(--accent2);
  border-radius: 8px;
  padding: 10px 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  animation: toast-in 0.3s ease;
}
.toast-title { font-size: 0.75rem; color: var(--accent2); }
.toast-name { font-weight: bold; }
.toast-out { opacity: 0; transform: translateX(20px); transition: all 0.5s; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

footer#page-footer { text-align: center; color: var(--muted); font-size: 0.78rem; margin-top: 16px; }

/* ---------- 脱走中のビネット演出 ---------- */
#breach-vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  box-shadow: inset 0 0 0 rgba(255,0,0,0);
  animation: vignette-pulse 1.4s infinite;
}
@keyframes vignette-pulse {
  0%, 100% { box-shadow: inset 0 0 80px rgba(200,0,0,0.15); }
  50% { box-shadow: inset 0 0 160px rgba(255,0,0,0.4); }
}

/* ---------- 画面フラッシュ ---------- */
.screen-flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 9500;
  animation: screen-flash-anim 0.45s ease-out forwards;
}
.screen-flash-red { background: rgba(255,40,40,0.35); }
.screen-flash-green { background: rgba(60,255,140,0.28); }
@keyframes screen-flash-anim {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- セルのシェイク ---------- */
@keyframes fx-shake-kf {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@keyframes fx-shake-big-kf {
  0%, 100% { transform: translate(0,0) rotate(0); }
  15% { transform: translate(-8px, 2px) rotate(-1deg); }
  30% { transform: translate(7px, -2px) rotate(1deg); }
  45% { transform: translate(-6px, 2px) rotate(-1deg); }
  60% { transform: translate(6px, -1px) rotate(1deg); }
  80% { transform: translate(-3px, 1px) rotate(0); }
}
.fx-shake { animation: fx-shake-kf 0.4s ease-in-out; }
.fx-shake-big { animation: fx-shake-big-kf 0.5s ease-in-out; }

/* ---------- フローティングテキスト ---------- */
.fx-float {
  position: fixed;
  z-index: 9600;
  font-weight: bold;
  font-size: 0.95rem;
  pointer-events: none;
  transform: translate(-50%, 0);
  animation: fx-float-anim 1.1s ease-out forwards;
  text-shadow: 0 2px 6px rgba(0,0,0,0.8);
}
.fx-good { color: var(--ok); }
.fx-normal { color: #cfd8e6; }
.fx-bad { color: var(--danger); }
@keyframes fx-float-anim {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(0.9); }
  15% { opacity: 1; transform: translate(-50%, -6px) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(1); }
}

/* ---------- サウンドトグル ---------- */
#sound-toggle { min-width: 40px; }

/* ---------- チュートリアル(スポットライト式) ---------- */
.tutorial-cta { border-color: var(--accent2); color: var(--accent2); font-weight: bold; }
#tutorial-root { display: none; }
.tut-mask {
  position: fixed;
  background: rgba(4, 5, 8, 0.78);
  z-index: 9998;
  transition: all 0.2s ease;
}
#tut-ring {
  position: fixed;
  display: none;
  border: 2px solid var(--accent2);
  border-radius: 8px;
  box-shadow: 0 0 0 3px rgba(255, 210, 77, 0.25), 0 0 18px rgba(255, 210, 77, 0.5);
  z-index: 9998;
  pointer-events: none;
  transition: all 0.2s ease;
  animation: tut-pulse 1.6s infinite;
}
@keyframes tut-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255,210,77,0.25), 0 0 14px rgba(255,210,77,0.4); }
  50% { box-shadow: 0 0 0 5px rgba(255,210,77,0.35), 0 0 22px rgba(255,210,77,0.65); }
}
#tut-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--panel);
  border: 1.5px solid var(--accent2);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.6);
}
#tut-progress { font-size: 0.7rem; color: var(--accent2); letter-spacing: 0.06em; margin-bottom: 4px; font-weight: bold; }
#tut-title { font-size: 1.05rem; font-weight: bold; margin-bottom: 6px; }
#tut-body { font-size: 0.87rem; line-height: 1.6; color: var(--text); }
#tut-hint { margin-top: 10px; font-size: 0.8rem; padding: 6px 8px; border-radius: 6px; display: none; }
.tut-hint-pending { background: #2a2210; color: var(--accent2); border: 1px dashed var(--accent2); }
.tut-hint-done { background: #10281c; color: var(--ok); border: 1px solid var(--ok); }
#tut-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
#tut-buttons #tut-skip { margin-right: auto; color: var(--muted); border-color: transparent; }
#tut-buttons #tut-next { border-color: var(--accent2); font-weight: bold; }
#tut-buttons #tut-next:disabled { opacity: 0.45; cursor: not-allowed; }
