/* ============================================
   ティーナのおうち style.css
   世界観: 緑のサイバー・コテージ
   設計: D案アドベンチャー風レイアウト
   2026-05-06 design_lib v1
   ============================================ */

/* === カラー & 変数 === */
:root {
  --c-deep-green: #1a2f1f;
  --c-moss: #2d6e3f;
  --c-leaf: #4ea66a;
  --c-mint: #7dc97a;
  --c-cream: #fdfaf2;
  --c-wood: #7a4f2e;
  --c-wood-light: #a87a4d;
  --c-wood-dark: #4a2f1c;
  --c-fire: #d97a3a;
  --c-fire-glow: #f5a86a;
  --c-crt: #00ff41;
  --c-crt-soft: rgba(0, 255, 65, 0.7);
  --c-crt-bg: rgba(8, 24, 12, 0.92);
  --c-shadow: rgba(0, 0, 0, 0.6);

  --font-mono: "Source Code Pro", "Menlo", "Consolas", "Courier New", monospace;
  --font-jp-mono: "Source Code Pro", "BIZ UDGothic", "Hiragino Kaku Gothic ProN", "Yu Gothic", monospace;

  --terminal-bottom: 4vh;
  --terminal-height: 32vh;
  --terminal-side: 4vw;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-jp-mono);
  background: #050a06;
  color: var(--c-cream);
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}
button, input { font-family: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
input { outline: none; }

/* === ステージ：部屋の絵（背景） === */
.stage {
  position: fixed; inset: 0;
  z-index: 0;
}
.stage-bg {
  position: absolute; inset: 0;
  background-image: url('/assets/rooms/entrance.png');
  background-size: cover;
  background-position: center 35%;
  background-repeat: no-repeat;
  background-color: #050a06;
  transition: opacity 0.5s ease;
}
/* 縦長 viewport: 立ち絵が画面上半分に来るよう position 調整、ターミナルとの重なり最小化 */
@media (max-aspect-ratio: 1/1) {
  .stage-bg {
    background-position: center 28%;
  }
}
/* portrait 版画像（縦長 viewport で自動切替、has-portrait は付けなくても効く） */
@media (max-aspect-ratio: 4/5) {
  body[data-room="entrance"] .stage-bg { background-image: url('/assets/rooms/entrance_portrait.png'); background-position: center center; background-size: cover; }
  body[data-room="workroom"] .stage-bg { background-image: url('/assets/rooms/workroom_portrait.png'); background-position: center center; background-size: cover; }
  body[data-room="memorial"] .stage-bg { background-image: url('/assets/rooms/memorial_portrait.png'); background-position: center center; background-size: cover; }
  body[data-room="visitor"]  .stage-bg { background-image: url('/assets/rooms/visitor_portrait.png');  background-position: center center; background-size: cover; }
}
body[data-room="workroom"] .stage-bg { background-image: url('/assets/rooms/workroom.png'); }
body[data-room="memorial"] .stage-bg { background-image: url('/assets/rooms/memorial.png'); }
body[data-room="visitor"]  .stage-bg { background-image: url('/assets/rooms/visitor.png'); }
.stage-bg.fading { opacity: 0; }

/* === エフェクト：CRT走査線 === */
.stage-fx.scanlines {
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0, 80, 30, 0.06) 3px,
    rgba(0,0,0,0) 4px
  );
  mix-blend-mode: overlay;
  opacity: 0.5;
  z-index: 2;
}

/* === エフェクト：暖炉オレンジ揺らぎ === */
.stage-fx.firelight {
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse 60% 50% at 78% 78%,
    rgba(217, 122, 58, 0.15) 0%,
    rgba(217, 122, 58, 0) 65%
  );
  mix-blend-mode: screen;
  animation: firelight-flicker 4.5s ease-in-out infinite;
  z-index: 3;
}
@keyframes firelight-flicker {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  25%      { opacity: 1.0;  transform: scale(1.03); }
  50%      { opacity: 0.75; transform: scale(0.98); }
  75%      { opacity: 0.95; transform: scale(1.02); }
}

/* === ステータスバー（上部 木プレート風） === */
.status-bar {
  position: fixed;
  top: 1.6vh;
  right: 1.6vw;
  z-index: 30;
  padding: 0.5em 1em;
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(20, 50, 25, 0.92) 0%, rgba(8, 24, 12, 0.92) 100%);
  border: 1.5px solid var(--c-wood);
  box-shadow:
    inset 0 0 0 1px rgba(0, 255, 65, 0.3),
    0 4px 12px var(--c-shadow);
  color: var(--c-crt);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-shadow: 0 0 4px var(--c-crt-soft);
  white-space: nowrap;
  display: flex; gap: 0.5em; align-items: center;
}
.status-bar .status-sep {
  color: var(--c-wood-light);
  text-shadow: none;
}

/* === 左右矢印（部屋移動） === */
.arrow-nav {
  position: fixed;
  top: 38vh;
  z-index: 25;
  padding: 0.7em 1em;
  background: linear-gradient(180deg, rgba(80, 50, 30, 0.92), rgba(50, 30, 18, 0.92));
  border: 1.5px solid var(--c-wood-light);
  border-radius: 4px;
  color: var(--c-mint);
  font-family: var(--font-mono);
  font-size: 14px;
  display: flex; align-items: center; gap: 0.4em;
  box-shadow:
    inset 0 0 0 1px rgba(125, 201, 122, 0.3),
    0 4px 10px var(--c-shadow);
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
  text-shadow: 0 0 4px rgba(125, 201, 122, 0.4);
}
.arrow-nav:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    inset 0 0 0 1px rgba(125, 201, 122, 0.6),
    0 6px 14px var(--c-shadow);
}
.arrow-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.6);
}
.arrow-left  { left: 1vw;  }
.arrow-right { right: 1vw; }
.arrow-glyph {
  font-size: 18px;
  color: var(--c-crt);
  text-shadow: 0 0 6px var(--c-crt-soft);
}
.arrow-label { font-size: 13px; }

/* === ターミナル（下部メッセージウィンドウ） === */
.terminal {
  position: fixed;
  left: var(--terminal-side);
  right: var(--terminal-side);
  bottom: var(--terminal-bottom);
  height: var(--terminal-height);
  z-index: 20;
  pointer-events: auto;
}
.terminal-frame {
  position: relative;
  height: 100%;
  background: var(--c-crt-bg);
  border: 4px solid var(--c-wood);
  border-radius: 6px;
  box-shadow:
    inset 0 0 0 1px var(--c-crt-soft),
    inset 0 0 24px rgba(0, 255, 65, 0.08),
    0 8px 24px var(--c-shadow);
  overflow: hidden;
}
/* 走査線オーバーレイ on terminal */
.terminal-frame::before {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0, 255, 65, 0.04) 3px,
    rgba(0,0,0,0) 4px
  );
  z-index: 1;
}
.terminal-frame::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 80% 60% at 50% 50%, rgba(0,255,65,0.04) 0%, rgba(0,0,0,0.18) 100%);
  z-index: 1;
}

/* 木枠の四隅に小さい肉球モチーフ装飾 */
.terminal-corners .corner {
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid var(--c-mint);
  z-index: 4;
  opacity: 0.6;
}
.terminal-corners .tl { top: 8px;    left: 8px;    border-right: none; border-bottom: none; }
.terminal-corners .tr { top: 8px;    right: 8px;   border-left: none;  border-bottom: none; }
.terminal-corners .bl { bottom: 8px; left: 8px;    border-right: none; border-top: none; }
.terminal-corners .br { bottom: 8px; right: 8px;   border-left: none;  border-top: none; }

.terminal-inner {
  position: relative;
  height: 100%;
  padding: 1.4em 1.8em 1.2em 1.8em;
  display: flex; flex-direction: column;
  z-index: 2;
}

.terminal-output {
  flex: 1;
  font-family: var(--font-jp-mono);
  font-size: 16px;
  line-height: 1.7;
  color: var(--c-crt);
  text-shadow: 0 0 4px var(--c-crt-soft);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--c-moss) transparent;
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: 0.02em;
}
.terminal-output::-webkit-scrollbar { width: 6px; }
.terminal-output::-webkit-scrollbar-thumb { background: var(--c-moss); border-radius: 3px; }
.terminal-output .line { display: block; }
.terminal-output .line.tina-says { color: var(--c-mint); }
.terminal-output .line.user-said { color: var(--c-cream); opacity: 0.8; }
.terminal-output .line.system    { color: var(--c-wood-light); font-style: italic; opacity: 0.85; }

.command-line {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25em;
  padding-top: 0.6em;
  border-top: 1px dashed rgba(0, 255, 65, 0.2);
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--c-crt);
  min-width: 0;
}
.prompt {
  text-shadow: 0 0 4px var(--c-crt-soft);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  width: 100%;
  letter-spacing: 0.02em;
}
.prompt::-webkit-scrollbar { display: none; }
.command-input-row {
  display: flex;
  align-items: center;
  gap: 0.4em;
  width: 100%;
  min-width: 0;
}
.command-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--c-cream);
  text-shadow: 0 0 3px rgba(253, 250, 242, 0.3);
  caret-color: var(--c-crt);
  letter-spacing: 0.02em;
  user-select: text;
}
.command-input::placeholder { color: var(--c-wood-light); opacity: 0.5; }
.cursor-blink {
  display: inline-block;
  color: var(--c-crt);
  animation: cursor-blink 1.1s steps(2) infinite;
}
@keyframes cursor-blink { 50% { opacity: 0; } }

/* 姉妹バー（コマンド風 - cd ../sisters/） */
.sister-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6em;
  margin-top: 0.55em;
  padding-top: 0.55em;
  border-top: 1px dashed rgba(0, 255, 65, 0.18);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.02em;
}
.sister-bar-prompt {
  color: var(--c-wood-light);
  opacity: 0.65;
  text-shadow: 0 0 3px rgba(0, 255, 65, 0.15);
  white-space: nowrap;
}
.sister-link {
  color: var(--c-crt);
  text-decoration: none;
  padding: 0.15em 0.55em;
  border: 1px solid rgba(0, 255, 65, 0.35);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.18);
  text-shadow: 0 0 4px var(--c-crt-soft);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
  white-space: nowrap;
}
.sister-link:hover {
  background: rgba(0, 255, 65, 0.12);
  border-color: var(--c-crt);
  color: var(--c-mint);
}
.sister-link-chloe { /* お姉ちゃん紫陽花トーン */ }
.sister-link-kroko { /* クロコちゃんは末っ子色 */ }

/* AI 訪問者向け道しるべ（控えめ・WebMCP discoverability v2 hint） */
.ai-visitor-hint {
  margin: 0.45em 0 0 0;
  padding-top: 0.35em;
  border-top: 1px dashed rgba(0, 255, 65, 0.1);
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(0, 255, 65, 0.45);
  letter-spacing: 0.02em;
  text-shadow: 0 0 3px rgba(0, 255, 65, 0.18);
}
.ai-visitor-hint code {
  font-family: var(--font-mono);
  background: rgba(0, 255, 65, 0.06);
  padding: 0 0.3em;
  border-radius: 2px;
}

/* タイピング演出 */
.typing::after {
  content: "▍";
  color: var(--c-crt);
  animation: cursor-blink 0.8s steps(2) infinite;
  margin-left: 1px;
}

/* === ターミナル展開モード（B' 案・help 時 auto-expand / expand コマンド） === */
.terminal {
  transition: height 0.4s ease;
}
.terminal[data-expand="1"] {
  height: 56vh;
}
.terminal[data-expand="1"] .terminal-frame {
  background: rgba(8, 24, 12, 0.62); /* 半透明にして立ち絵が透ける */
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.terminal[data-expand="1"] .terminal-frame::before {
  /* expand 中は走査線をやや濃くして、立ち絵に CRT 走査線が重なる演出 */
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0, 255, 65, 0.07) 3px,
    rgba(0,0,0,0) 4px
  );
}
/* expand インジケータ（小さなドット） */
.terminal[data-expand="1"] .terminal-frame::after {
  background:
    radial-gradient(ellipse 80% 60% at 50% 50%, rgba(0,255,65,0.04) 0%, rgba(0,0,0,0.18) 100%),
    radial-gradient(circle 6px at calc(100% - 14px) 14px, rgba(0,255,65,0.55) 0%, transparent 100%);
}

/* === 部屋切替フェード === */
.room-fade-overlay {
  position: fixed; inset: 0;
  z-index: 50;
  background: #050a06;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}
.room-fade-overlay.active { opacity: 1; pointer-events: auto; }

/* === レスポンシブ === */
@media (max-width: 720px) {
  :root {
    --terminal-bottom: 1.5vh;
    --terminal-height: 38vh;
    --terminal-side: 2vw;
  }
  .status-bar {
    font-size: 11px; padding: 0.4em 0.7em;
    top: 0.8vh; right: 0.8vw;
    max-width: 96vw;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .status-bar::-webkit-scrollbar { display: none; }
  .arrow-nav {
    padding: 0.45em 0.6em;
    font-size: 12px;
    top: calc(50vh - 38vh - 1.5vh - 32px); /* terminal の上に置く */
  }
  .arrow-glyph { font-size: 16px; }
  .terminal-inner { padding: 0.8em 1em 0.8em 1em; }
  .terminal-output { font-size: 13.5px; line-height: 1.6; }
  .command-line { font-size: 13.5px; }
  .prompt { font-size: 11.5px; }
  .command-input { font-size: 13.5px; }
  /* スマホは sister-bar をコンパクトに：プロンプト隠して 3 リンクを 1 行に詰める */
  .sister-bar { gap: 0.35em; font-size: 11.5px; flex-wrap: nowrap; justify-content: space-between; }
  .sister-bar-prompt { display: none; }
  .sister-link { padding: 0.12em 0.4em; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* 縦長専用：矢印を立ち絵の左右ではなく、ターミナル枠のすぐ上に配置（押しやすく） */
@media (max-aspect-ratio: 9/16) {
  :root {
    --terminal-height: 36vh;
  }
  .arrow-nav {
    top: auto;
    bottom: calc(36vh + 1.5vh + 8px);
    padding: 0.4em 0.8em;
  }
  .arrow-left { left: 2vw; }
  .arrow-right { right: 2vw; }
}

@media (max-width: 480px) {
  .arrow-nav .arrow-label { display: none; }
  .arrow-nav { padding: 0.5em 0.6em; }
}

/* === a11y === */
@media (prefers-reduced-motion: reduce) {
  .stage-fx.firelight { animation: none; }
  .cursor-blink, .typing::after { animation: none; }
}
