/* LifeCachePurge - Base CSS（レトロOS「LifeOS」テーマ：トークン・部品・汎用画面） */

@font-face {
  font-family: "DotGothic16";
  src: url("../assets/fonts/DotGothic16-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: light;

  /* 壁紙（章ごとに上書き） */
  --desk: #1f5a62;
  --desk-dither: #1b5058;

  /* ウィンドウの面と立体（ベベル） */
  --face: #d6d2c8;
  --face-hi: #fbfaf5;
  --face-lt: #ebe8e0;
  --face-lo: #8d897f;
  --face-dk: #2c2a26;
  --field: #fbfaf5;
  --ink: #17150f;
  --ink-muted: #5c584e;

  /* タイトルバー（章ごとに上書き） */
  --title-a: #0f2466;
  --title-b: #3a6cc2;
  --title-off-a: #7d7a72;
  --title-off-b: #b2aea4;
  --sel: #0f2466;
  --sel-ink: #ffffff;

  /* 意味の色（明るい面の上で読める濃さ） */
  --accent: #1d4fae;
  --danger: #b3141a;
  --danger-bg: #f7d9d6;
  --warn: #8a5800;
  --warn-bg: #fbefc8;
  --success: #116b31;
  --success-bg: #d6efd9;
  --gold: #8a6400;

  /* ツールチップ・吹き出し */
  --balloon: #ffffe1;

  /* ターミナル */
  --term-bg: #0b0f0b;
  --term-fg: #8ff0a4;

  /* 立体の影 */
  --raised: inset -1px -1px var(--face-dk), inset 1px 1px var(--face-hi), inset -2px -2px var(--face-lo), inset 2px 2px var(--face-lt);
  --pressed: inset 1px 1px var(--face-dk), inset -1px -1px var(--face-hi), inset 2px 2px var(--face-lo), inset -2px -2px var(--face-lt);
  --sunken: inset 1px 1px var(--face-lo), inset -1px -1px var(--face-hi), inset 2px 2px var(--face-dk), inset -2px -2px var(--face-lt);
  --drop: 4px 4px 0 rgba(0, 0, 0, 0.28);

  --font-pixel: "DotGothic16", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", monospace;
  --font-sans: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* 旧トークン名（JS のインライン指定が参照している） */
  --fg: var(--ink);
  --fg-muted: var(--ink-muted);
  --border: var(--face-lo);
  --panel: var(--face);
  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;
}

/* 章ごとの空気（壁紙とタイトルバー） */
[data-chapter="2"] {
  --desk: #3c4654;
  --desk-dither: #36404d;
  --title-a: #24384a;
  --title-b: #5f8297;
  --sel: #24384a;
}

[data-chapter="3"] {
  --desk: #5d4b3b;
  --desk-dither: #554435;
  --title-a: #5a3b1f;
  --title-b: #a98559;
  --sel: #5a3b1f;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: clamp(13px, 0.45vw + 9px, 17px);
}

html, body {
  height: 100%;
}

body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background-color: var(--desk);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* 壁紙: 2px のディザ */
.wallpaper,
body {
  background-image:
    linear-gradient(45deg, var(--desk-dither) 25%, transparent 25%, transparent 75%, var(--desk-dither) 75%),
    linear-gradient(45deg, var(--desk-dither) 25%, transparent 25%, transparent 75%, var(--desk-dither) 75%);
  background-size: 4px 4px;
  background-position: 0 0, 2px 2px;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px dotted var(--ink);
  outline-offset: -5px;
}

/* 画面共通 */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.screen[hidden] {
  display: none !important;
}

/* 中央寄せの画面（タイトル・設定・図鑑など）: 壁紙の上にウィンドウを1枚置く */
/* はみ出したときに上端が切れないよう、中央寄せは auto マージンで行う */
.center-screen {
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem;
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===================================================
   ウィンドウ（共通の枠）
   =================================================== */
.os-window {
  background: var(--face);
  box-shadow: var(--raised), var(--drop);
  padding: 3px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  color: var(--ink);
}

.os-titlebar,
.win-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 1.9rem;
  padding: 0.15rem 0.35rem 0.15rem 0.5rem;
  background: linear-gradient(90deg, var(--title-a), var(--title-b));
  color: #fff;
  font-family: var(--font-pixel);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.os-titlebar > :first-child,
.win-header > :first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win-header > :last-child:not(:first-child) {
  font-size: 0.85rem;
  opacity: 0.92;
}

/* 飾りの最小化・最大化・閉じる */
.os-controls {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.os-controls span {
  width: 1.1rem;
  height: 1rem;
  background: var(--face);
  box-shadow: var(--raised);
  color: var(--ink);
  font-size: 0.7rem;
  line-height: 1rem;
  text-align: center;
  font-family: var(--font-mono);
}

.os-body {
  flex: 1;
  min-height: 0;
  padding: 0.9rem 1rem;
  overflow-y: auto;
}

/* 白い入力欄・リストのくぼみ */
.os-field {
  background: var(--field);
  box-shadow: var(--sunken);
  padding: 4px;
}

/* ===================================================
   ボタン
   =================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.45rem 1.1rem;
  border: none;
  border-radius: 0;
  background: var(--face);
  box-shadow: var(--raised);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:hover:not(:disabled) {
  background: var(--face-lt);
}

.btn:active:not(:disabled) {
  box-shadow: var(--pressed);
  padding-top: calc(0.45rem + 1px);
  padding-left: calc(1.1rem + 1px);
}

.btn:disabled {
  color: var(--face-lo);
  text-shadow: 1px 1px 0 var(--face-hi);
  cursor: not-allowed;
}

/* 既定ボタン（Enter で押されるもの）: 外側の黒枠 */
.btn-primary {
  box-shadow: 0 0 0 1px var(--face-dk), var(--raised);
}

.btn-primary:active:not(:disabled) {
  box-shadow: 0 0 0 1px var(--face-dk), var(--pressed);
}

.btn-danger {
  color: var(--danger);
}

.btn-sub {
  font-weight: 600;
}

/* ===================================================
   タイトル画面
   =================================================== */
.center-screen > :first-child {
  margin-top: auto;
}

.center-screen > :last-child {
  margin-bottom: auto;
}

.title-window {
  width: min(560px, 100%);
  flex-shrink: 0;
}

.title-window .os-body {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.25rem 1.5rem;
  padding: 1.5rem 1.6rem 1.4rem;
}

.title-emblem {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  align-self: start;
}

.title-logo-box {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.title-tagline {
  font-family: var(--font-pixel);
  font-size: 0.8rem;
  color: var(--ink-muted);
  letter-spacing: 0.08em;
}

h1.game-title {
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: clamp(1.7rem, 2.4vw + 0.6rem, 2.4rem);
  line-height: 1.15;
  color: var(--ink);
}

.title-concept {
  font-size: 0.9rem;
  color: var(--ink-muted);
  line-height: 1.6;
}

.title-menu {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.title-menu .btn-primary,
.title-menu #btn-continue {
  grid-column: span 1;
  min-height: 52px;
  font-size: 1.05rem;
}

.title-footer {
  margin-top: 1rem;
  font-family: var(--font-pixel);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
  text-align: center;
}

/* ===================================================
   汎用画面（チャプター選択・図鑑・設定・エンディング）
   =================================================== */
.panel-window {
  width: min(720px, 100%);
  max-height: 100%;
}

.panel-window .os-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-lead {
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem 0.8rem;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--field);
  box-shadow: var(--sunken);
  padding: 4px;
  text-align: left;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.8rem;
  border-bottom: 1px dotted var(--face-lo);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-item.is-summary {
  background: var(--face-lt);
  font-size: 0.85rem;
}

.settings-label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.settings-label span:first-child {
  font-weight: 700;
  font-size: 0.95rem;
}

.settings-label span:last-child {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.kb-kind {
  font-family: var(--font-pixel);
  font-size: 0.78rem;
  color: var(--accent);
}

.kb-action {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-muted);
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--title-a);
  cursor: pointer;
  flex-shrink: 0;
}

.os-select {
  min-height: 36px;
  padding: 0 0.5rem;
  border: none;
  border-radius: 0;
  background: var(--field);
  box-shadow: var(--sunken);
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
}

input[type="range"] {
  width: 160px;
  accent-color: var(--title-a);
  cursor: pointer;
  flex-shrink: 0;
}

/* ===================================================
   モーダル（OS のダイアログ）
   =================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 14, 20, 0.45);
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  width: min(460px, 100%);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--face);
  box-shadow: var(--raised), var(--drop);
  padding: 3px;
  display: flex;
  flex-direction: column;
}

/* モーダルのタイトル行はタイトルバーとして描く */
.modal-card > .modal-title,
.modal-card > .help-header {
  margin: 0;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 1.9rem;
  padding: 0.15rem 0.5rem;
  background: linear-gradient(90deg, var(--title-a), var(--title-b));
  color: #fff !important;
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 0.95rem;
}

.modal-body {
  padding: 1rem 1.1rem 0.5rem;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--ink);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem 0.9rem;
}

.modal-actions .btn {
  min-width: 7.5rem;
}

.modal-actions.is-stacked {
  flex-direction: column;
  align-items: stretch;
}

/* ===================================================
   低い画面（スマホ横向きなど）
   =================================================== */
@media (max-height: 480px) {
  .center-screen {
    justify-content: flex-start;
    padding: 0.75rem;
  }

  .title-window .os-body {
    padding: 0.9rem 1rem;
    gap: 0.75rem 1rem;
  }

  .title-emblem {
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 560px) {
  .title-window .os-body {
    grid-template-columns: 1fr;
  }

  .title-emblem {
    display: none;
  }

  .title-menu {
    grid-template-columns: 1fr;
  }

  .settings-item {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
