/* ==========================================================================
   yutat23.com — MOTHER2(EARTHBOUND)風Ver スタイルシート
   構成: ベース / ウィンドウ共通 / レイアウト / メッセージ / コマンド /
         ステージ / ステータス / WORKS / オーバーレイ / メディアクエリ
   ========================================================================== */

* {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   ベース
   -------------------------------------------------------------------------- */
html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "DotGothic16", "Noto Sans JP", monospace;
  -webkit-user-select: none;
  user-select: none;
}

/* サイケデリック背景(低解像度キャンバスを引き伸ばしてドット感を出す) */
#bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  z-index: 0;
}

/* --------------------------------------------------------------------------
   ウィンドウ共通(黒地 + 白の丸角フレーム)
   -------------------------------------------------------------------------- */
.eb-window {
  background: linear-gradient(180deg, #1c1c34 0%, #0c0c1c 100%);
  border: 3px solid #f8f8f8;
  border-radius: 10px;
  /* 外側の黒フチと内側の黒ラインで二重枠に見せる */
  box-shadow: 0 0 0 3px #000, inset 0 0 0 2px #000;
  color: #f8f8f8;
}

.eb-window.mini {
  padding: 5px 10px;
  font-size: 12px;
  border-width: 2px;
  border-radius: 8px;
  box-shadow: 0 0 0 2px #000, inset 0 0 0 1px #000;
}

.hidden {
  display: none !important;
}

.blink {
  animation: blink 0.8s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   レイアウト
   -------------------------------------------------------------------------- */
#game {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px;
  gap: 12px;
}

#top-bar {
  width: min(94vw, 640px);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#ver-link {
  color: #f8f8f8;
  text-decoration: none;
}

#ver-link:hover {
  background: #2c2c4c;
}

#sound-toggle {
  font-family: inherit;
  color: #f8f8f8;
  cursor: pointer;
}

#sound-toggle:hover {
  background: #2c2c4c;
}

#column {
  width: min(94vw, 640px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

/* --------------------------------------------------------------------------
   メッセージウィンドウ
   -------------------------------------------------------------------------- */
#msg-window {
  position: relative;
  width: 100%;
  min-height: 100px;
  padding: 14px 18px;
  font-size: 18px;
  line-height: 1.8;
  cursor: pointer;
}

#msg-text {
  margin: 0;
  white-space: pre-line;
}

#msg-cursor {
  position: absolute;
  right: 16px;
  bottom: 8px;
  font-size: 14px;
}

/* --------------------------------------------------------------------------
   SMAAAASH!!(クリティカル)バナー
   低解像度キャンバスに描いた飾り文字を整数倍に拡大してドット絵にする
   (描画内容はJSの renderSmashBanner が作る)
   -------------------------------------------------------------------------- */
#smash-banner {
  display: block;
  margin: 0;
  max-width: 100%;
  image-rendering: pixelated;
  transform-origin: left center;
}

/* 出現時にカクカクと弾けるように拡大する */
#smash-banner.is-active {
  animation: smash-pop 0.24s steps(3, end);
}

@keyframes smash-pop {
  0% {
    transform: scale(0.4);
  }
  60% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

/* 致命傷を受けた瞬間の画面シェイク(bodyごと揺らして全レイヤーを動かす) */
body.screen-shake {
  animation: screen-shake 0.45s linear;
}

@keyframes screen-shake {
  0%,
  100% {
    transform: translateY(0);
  }
  15% {
    transform: translateY(-12px);
  }
  30% {
    transform: translateY(10px);
  }
  45% {
    transform: translateY(-8px);
  }
  60% {
    transform: translateY(6px);
  }
  80% {
    transform: translateY(-3px);
  }
}

/* --------------------------------------------------------------------------
   バトルコマンド
   -------------------------------------------------------------------------- */
#cmd-window {
  position: relative;
  min-width: 380px;
  padding: 14px 20px 12px;
}

/* 本家風にウィンドウ上枠へ持ち主の名前タグを重ねる */
#cmd-owner,
#psi-owner {
  position: absolute;
  top: -14px;
  left: 14px;
  background: #0c0c1c;
  border: 2px solid #f8f8f8;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #000;
  padding: 1px 8px;
  font-size: 12px;
  line-height: 1.5;
}

#cmd-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px 24px;
  font-size: 18px;
}

#cmd-list li {
  position: relative;
  padding-left: 1.3em;
  cursor: pointer;
  white-space: nowrap;
}

#cmd-list li.selected::before {
  content: "▶";
  position: absolute;
  left: 0;
}

/* --------------------------------------------------------------------------
   PSI選択ウィンドウ
   -------------------------------------------------------------------------- */
#psi-window {
  position: relative;
  min-width: 320px;
  padding: 14px 20px 12px;
}

#psi-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 17px;
}

#psi-list li {
  position: relative;
  padding-left: 1.3em;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  cursor: pointer;
  white-space: nowrap;
}

#psi-list li.selected::before {
  content: "▶";
  position: absolute;
  left: 0;
}

/* PPが足りない技は薄く表示する */
#psi-list li.unaffordable {
  color: #8888a0;
}

#psi-list .psi-cost {
  font-size: 14px;
  align-self: center;
}

/* --------------------------------------------------------------------------
   ステージ(敵スプライト)
   -------------------------------------------------------------------------- */
#stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#enemy {
  width: 256px;
  height: 256px;
  image-rendering: pixelated;
  cursor: pointer;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35));
  animation: enemy-bob 2.4s ease-in-out infinite;
}

@keyframes enemy-bob {
  50% {
    transform: translateY(-6px);
  }
}

/* たたかれたときのシェイク(クラスは演出後にJSが外す) */
#enemy.hit {
  animation: enemy-hit 0.35s linear;
}

@keyframes enemy-hit {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(7px);
  }
  60% {
    transform: translateX(-5px);
  }
  80% {
    transform: translateX(4px);
  }
}

/* 撃破時は下へ潰れながら消え、復活時は逆方向に戻る */
#enemy.enemy-defeated {
  pointer-events: none;
  animation: enemy-fade-out 0.8s steps(10, end) forwards;
}

#enemy.enemy-reviving {
  animation: enemy-fade-in 0.8s steps(10, end) both;
}

@keyframes enemy-fade-out {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1, 1);
  }
  55% {
    opacity: 0.55;
    transform: translateY(10px) scale(1.06, 0.62);
  }
  100% {
    opacity: 0;
    transform: translateY(28px) scale(0.88, 0.06);
  }
}

@keyframes enemy-fade-in {
  0% {
    opacity: 0;
    transform: translateY(28px) scale(0.88, 0.06);
  }
  45% {
    opacity: 0.55;
    transform: translateY(10px) scale(1.06, 0.62);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1, 1);
  }
}

/* PSI発動時の画面フラッシュ */
#flash {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0;
}

#flash.is-active {
  animation: psi-flash 0.5s steps(1);
}

/* 属性ごとのフラッシュ色(指定なしは回復系の緑) */
#flash.fire {
  --f1: #fff0d8;
  --f2: #ff9838;
  --f3: #ffd8a0;
  --f4: #f85838;
}

#flash.freeze {
  --f1: #f0ffff;
  --f2: #88d8ff;
  --f3: #ffffff;
  --f4: #5898f8;
}

#flash.thunder {
  --f1: #ffffff;
  --f2: #fff860;
  --f3: #ffffff;
  --f4: #f8d820;
}

/* PSIエフェクト(低解像度キャンバスを画面全体に引き伸ばしてドット感を出す) */
#psi-fx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 80;
  pointer-events: none;
  image-rendering: pixelated;
}

@keyframes psi-flash {
  0% {
    background: var(--f1, #e8fff8);
    opacity: 0.85;
  }
  25% {
    background: var(--f2, #7cf8c8);
    opacity: 0.7;
  }
  50% {
    background: var(--f3, #c8f8ff);
    opacity: 0.8;
  }
  75% {
    background: var(--f4, #7cc8f8);
    opacity: 0.6;
  }
  100% {
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   ステータスウィンドウ
   -------------------------------------------------------------------------- */
#status-row {
  display: flex;
  gap: 14px;
}

/* 本家のパーティーステータス風: 明るいボックスに黒文字 */
.status-box {
  width: 140px;
  min-width: 0;
  padding: 7px 10px 9px;
  text-align: center;
  text-shadow: 1px 1px 0 #403450;
  font-size: 17px;
  line-height: 1.4;
  background-color: #8878ac;
  background-image: linear-gradient(45deg, #9c8cbc 25%, transparent 25%),
    linear-gradient(-45deg, #9c8cbc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #9c8cbc 75%),
    linear-gradient(-45deg, transparent 75%, #9c8cbc 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  border-color: #101018;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #e0e4ec, inset 0 0 0 2px #8c90a0;
  color: #101018;
}

.status-name {
  margin: 0 0 4px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  outline: 0;
  color: #f8f8f8;
  text-align: left;
  text-shadow: 1px 1px 0 #403450;
  letter-spacing: 1px;
  font-size: 20px;
  line-height: 1.2;
}

.status-stat {
  display: grid;
  grid-template-columns: 48px max-content;
  align-items: center;
  justify-content: center;
  column-gap: 5px;
  margin-top: 3px;
}

.stat-label {
  background: transparent;
  border: 0;
  color: #f8f8f8;
  box-shadow: none;
  text-shadow: 1px 1px 0 #403450;
  font-size: 18px;
  line-height: 1;
  padding: 3px 4px 2px;
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   ドラムロールカウンタ(オドメーター)
   数字1桁ごとに0-9の帯を縦に並べ、transformで回転しているように見せる
   -------------------------------------------------------------------------- */
.odometer {
  --odo-h: 30px; /* 1桁分のセル高さ。JSはこの実測値で回す */
  display: flex;
  background: #e8e8dc;
  border: 2px solid #202028;
  border-radius: 2px;
  padding: 0 1px;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.35),
    inset 0 -2px 3px rgba(0, 0, 0, 0.25);
}

.odo-digit {
  position: relative;
  width: 0.85em;
  height: var(--odo-h);
  overflow: hidden;
  font-size: 22px;
}

.odo-digit + .odo-digit {
  border-left: 1px solid rgba(0, 0, 0, 0.25);
}

.odo-strip {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  will-change: transform;
}

.odo-cell {
  display: block;
  height: var(--odo-h);
  line-height: var(--odo-h);
  text-align: center;
}

/* --------------------------------------------------------------------------
   WORKS 一覧ウィンドウ
   -------------------------------------------------------------------------- */
#works-window {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  width: min(94vw, 620px);
  max-height: min(78vh, 560px);
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  gap: 10px;
}

#works-title {
  text-align: center;
  letter-spacing: 2px;
  flex-shrink: 0;
}

#works-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(248, 248, 248, 0.5) transparent;
}

#works-list::-webkit-scrollbar {
  width: 6px;
}

#works-list::-webkit-scrollbar-thumb {
  background: rgba(248, 248, 248, 0.5);
  border-radius: 3px;
}

.works-category {
  color: #ffd870;
  margin: 12px 0 4px;
  font-size: 14px;
  letter-spacing: 2px;
}

.works-category:first-child {
  margin-top: 0;
}

.works-item {
  position: relative;
  padding: 2px 4px 2px 1.4em;
  font-size: 16px;
  line-height: 1.7;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.works-item.selected::before {
  content: "▶";
  position: absolute;
  left: 2px;
}

#works-desc {
  flex-shrink: 0;
  border-top: 2px solid rgba(248, 248, 248, 0.4);
  padding-top: 8px;
  font-size: 14px;
  line-height: 1.6;
  min-height: 3.4em;
  white-space: pre-line;
  color: #d8d8e8;
}

#works-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

#works-hint {
  font-size: 11px;
  color: #9898b0;
}

#works-close {
  border: 0;
  padding: 2px 4px;
  background: transparent;
  color: #f8f8f8;
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

#works-close:hover,
#works-close:focus-visible {
  color: #ffd870;
  outline: none;
  text-shadow: 0 0 5px rgba(255, 216, 112, 0.55);
}

/* --------------------------------------------------------------------------
   CRTスキャンライン風オーバーレイ
   -------------------------------------------------------------------------- */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* --------------------------------------------------------------------------
   メディアクエリ
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .blink {
    animation: none;
  }
  #enemy,
  #enemy.hit {
    animation: none;
  }
  #enemy.enemy-defeated {
    animation: none;
    opacity: 0;
    transform: translateY(28px) scale(0.88, 0.06);
  }
  #enemy.enemy-reviving {
    animation: none;
    opacity: 1;
    transform: none;
  }
  #flash.is-active {
    animation: none;
  }
  #smash-banner.is-active {
    animation: none;
  }
  body.screen-shake {
    animation: none;
  }
}

@media (max-width: 520px) {
  #game {
    padding: 10px;
    gap: 10px;
  }
  #top-bar,
  #column {
    width: 100%;
  }
  .eb-window.mini {
    padding: 7px 10px;
    font-size: 13px;
  }
  #msg-window {
    min-height: 100px;
    padding: 14px 16px;
    font-size: 17px;
  }
  #cmd-window,
  #psi-window {
    min-width: 0;
    width: 100%;
  }
  #cmd-list {
    font-size: 17px;
    gap: 10px 14px;
  }
  #psi-list {
    font-size: 17px;
  }
  #enemy {
    width: clamp(140px, 42vw, 190px);
    height: auto;
    max-width: 30vh;
  }
  .status-box {
    width: 150px;
    min-width: 150px;
    padding: 7px 10px 9px;
    font-size: 20px;
  }
  .status-name {
    margin-bottom: 4px;
    padding: 0;
    font-size: 24px;
  }
  .status-stat {
    grid-template-columns: 58px max-content;
    column-gap: 4px;
    margin-top: 2px;
  }
  .stat-label {
    font-size: 22px;
    padding: 3px 5px 2px;
  }
  .odometer {
    --odo-h: 34px;
  }
  .odo-digit {
    font-size: 25px;
  }
  .works-item {
    font-size: 15px;
  }
  #works-hint {
    display: none;
  }
}
