/* css/desktop.css - デスクトップ（ゲーム本編）のレイアウトとタスクバー */

#screen-desktop {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

#screen-desktop[hidden] {
  display: none !important;
}

/* ===================================================
   ワークスペース: 左＝メイン（予定・場面・決算）/ 右＝ストレージ・ログ
   =================================================== */
#desktop-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(340px, 1fr);
  gap: 14px;
  padding: 14px;
}

#main-viewport-pane {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
}

#side-window-pane {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#storage-window-card {
  flex: 1;
  min-height: 0;
  background: var(--face);
  box-shadow: var(--raised), var(--drop);
  padding: 3px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* メイン列に並ぶウィンドウ */
.main-window {
  flex: 1;
  min-height: 0;
}

.main-window.is-compact {
  flex: 0 0 auto;
  max-height: 42%;
}

/* ===================================================
   朝: 今日の予定（場面プレビュー＋予定カード）
   =================================================== */
.brief-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0;
}

.brief-stage {
  position: relative;
  min-height: 0;
  background: #000;
  box-shadow: var(--sunken);
  margin: 6px 6px 0;
  overflow: hidden;
}

.brief-stage-caption {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 0.2rem 0.55rem;
  background: var(--balloon);
  color: var(--ink);
  font-family: var(--font-pixel);
  font-size: 0.85rem;
  box-shadow: 1px 1px 0 var(--face-dk);
}

.brief-schedule {
  display: flex;
  gap: 8px;
  padding: 10px 6px 6px;
  overflow-x: auto;
}

.schedule-card {
  flex: 1 1 0;
  min-width: 11rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.15rem 0.7rem;
  padding: 0.55rem 0.75rem;
  background: var(--field);
  box-shadow: var(--sunken);
}

.schedule-order {
  grid-row: span 2;
  font-family: var(--font-pixel);
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-muted);
}

.schedule-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
}

.schedule-req {
  grid-row: span 2;
  font-family: var(--font-pixel);
  font-size: 1.15rem;
  text-align: right;
  white-space: nowrap;
}

.schedule-state {
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.schedule-card.is-short .schedule-req,
.schedule-card.is-short .schedule-state {
  color: var(--danger);
}

.schedule-card.is-ok .schedule-state {
  color: var(--success);
}

.schedule-card.is-holiday {
  border-left: 4px solid var(--accent);
}

/* ===================================================
   昼: 場面ウィンドウ
   =================================================== */
/* 場面は 16:9、その下にメッセージ窓（ノベルゲームの配置） */
.scene-window .scene-stage {
  position: relative;
  flex: 0 1 auto;
  aspect-ratio: 16 / 9;
  min-height: 0;
  max-height: calc(100% - 9.5rem);
  margin: 6px 6px 0;
  background: #000;
  box-shadow: var(--sunken);
  overflow: hidden;
}

.scene-message-area {
  position: relative;
  flex: 1 0 9rem;
  min-height: 9rem;
  padding: 1.3rem 6px 6px;
}

#scene-container {
  position: absolute;
  inset: 0;
}

#scene-container canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: pixelated;
}

/* ===================================================
   タスクバー（日・予定・RAM・スロット・メニュー）
   =================================================== */
#taskbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 4px 6px;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
  background: var(--face);
  box-shadow: inset 0 1px var(--face-hi), inset 0 2px var(--face-lt), 0 -1px var(--face-lo);
  font-size: 0.9rem;
}

.tb-start {
  min-height: 38px;
  padding: 0 0.8rem;
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 1rem;
  gap: 0.35rem;
}

.tb-start .tb-logo {
  width: 18px;
  height: 18px;
  image-rendering: pixelated;
}

.tb-sep {
  width: 2px;
  align-self: stretch;
  margin: 4px 2px;
  box-shadow: inset 1px 0 var(--face-lo), inset -1px 0 var(--face-hi);
}

.tb-cell {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 34px;
  padding: 0 0.7rem;
  box-shadow: var(--sunken);
  background: var(--face);
  white-space: nowrap;
}

.hud-day-badge {
  font-family: var(--font-pixel);
  font-size: 1rem;
}

.hud-phase {
  font-family: var(--font-pixel);
  font-size: 0.85rem;
  padding: 0.05rem 0.45rem;
  background: var(--sel);
  color: var(--sel-ink);
}

.tb-plan {
  flex: 1;
  min-width: 0;
}

#hud-current-plan {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* RAM ゲージ: 空き容量をブロックで満たし、必要ラインを越えれば OK */
#ram-strip {
  flex: 0 1 34%;
  min-width: 260px;
  gap: 0.6rem;
}

.ram-bar-container {
  position: relative;
  flex: 1;
  height: 18px;
  background: var(--field);
  box-shadow: var(--sunken);
  padding: 3px;
}

.ram-bar-fill {
  height: 100%;
  width: 0;
  background-image: repeating-linear-gradient(90deg, var(--title-a) 0 8px, transparent 8px 10px);
  transition: width 0.25s steps(6);
}

.ram-bar-fill.is-short {
  background-image: repeating-linear-gradient(90deg, var(--danger) 0 8px, transparent 8px 10px);
}

.ram-bar-required-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  margin-left: -1px;
  background: var(--danger);
  box-shadow: 0 0 0 1px var(--field);
}

.ram-bar-required-marker::after {
  content: "必要";
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  line-height: 1;
  color: var(--danger);
  font-weight: 700;
  white-space: nowrap;
}

.ram-label {
  font-family: var(--font-pixel);
  font-size: 0.9rem;
}

.ram-label.is-short {
  color: var(--danger);
}

.hud-slots-badge {
  font-family: var(--font-pixel);
  letter-spacing: 0.05em;
}

.slot-pip {
  color: var(--title-a);
}

.slot-pip.is-empty {
  color: var(--face-lo);
}

.tb-clock {
  font-family: var(--font-pixel);
  min-width: 4.2rem;
  justify-content: center;
}

/* ===================================================
   スマホ・狭い画面（簡易レスポンシブ: 1列に積む）
   =================================================== */
@media (max-width: 899px) {
  #desktop-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  /* 朝: 予定は場面プレビューを省いて予定カードだけ、残りをストレージに */
  [data-phase="morning"] .brief-window .win-header {
    display: none;
  }

  [data-phase="morning"] #main-viewport-pane {
    max-height: 34vh;
  }

  .brief-schedule {
    padding: 4px;
  }

  .schedule-card {
    min-width: 9rem;
    padding: 0.4rem 0.6rem;
  }

  /* 昼・夜: メイン（場面・決算）を全面に、ログは隠す */
  [data-phase="day"] #desktop-workspace,
  [data-phase="night"] #desktop-workspace {
    grid-template-rows: minmax(0, 1fr);
  }

  [data-phase="day"] #side-window-pane,
  [data-phase="night"] #side-window-pane {
    display: none;
  }

  #taskbar {
    flex-wrap: wrap;
    gap: 4px;
  }

  .tb-plan,
  .tb-clock,
  .tb-sep {
    display: none;
  }

  #ram-strip {
    order: 10;
    flex: 1 1 100%;
    min-width: 0;
  }
}

@media (max-width: 899px) and (orientation: portrait) {
  [data-phase="morning"] .brief-stage {
    display: none;
  }

  [data-phase="morning"] .brief-body {
    grid-template-rows: auto;
  }
}

/* 低い画面ではストレージ窓の中身をまとめてスクロールさせる */
@media (max-height: 560px) {
  #storage-window-card .file-list-container {
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
  }
}

@media (max-width: 899px) and (orientation: landscape) {
  #desktop-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    grid-template-rows: minmax(0, 1fr);
  }

  [data-phase="morning"] #main-viewport-pane {
    max-height: none;
  }

  #ram-strip {
    order: 0;
    flex: 1 1 0;
  }
}

/* 昼の右列: 今日の進み具合 */
.day-progress {
  flex-shrink: 0;
  margin: 6px 6px 0;
  padding: 0.5rem 0.6rem;
  background: var(--face-lt);
  box-shadow: var(--sunken);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.day-progress-title {
  font-family: var(--font-pixel);
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.day-progress-item {
  display: grid;
  grid-template-columns: 1.4rem 1fr auto;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.9rem;
}

.day-progress-item.is-current {
  font-weight: 700;
}

.day-progress-item.is-done {
  color: var(--ink-muted);
}

.day-progress-req {
  font-family: var(--font-pixel);
}

.day-progress-item.is-short .day-progress-req {
  color: var(--danger);
}
