/* 夕暮れの地方都市を、PS1 世代の粗いドットで。紺＋黄枠の角丸コンテナ、上に重なるパネルは白いすりガラス */
:root {
  --ink: #0d1120;        /* 画面の地 */
  --navy: #1b2444;       /* コンテナ */
  --navy-2: #263259;
  --gold: #e8c547;       /* 黄枠・強調 */
  --paper: #f3ecd6;      /* 文字 */
  --dim: #9aa3c2;        /* 補助の文字 */
  --danger: #e0614f;
  --ok: #7fc98a;
  --glass: rgba(244, 246, 255, 0.74);
  --glass-ink: #1b2444;
  --font: 'DotGothic16', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font);
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; }

#app {
  container: app / size;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding-block: 8px;
  padding-left: max(10px, env(safe-area-inset-left, 0px));
  padding-right: max(10px, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
}

/* ステータスバー */
#status {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--navy);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 6px 8px;
  min-width: 0;
}
.stat { display: flex; align-items: baseline; gap: 6px; min-width: 0; white-space: nowrap; }
.stat .label { font-size: 11px; color: var(--dim); letter-spacing: .05em; }
.stat .val { font-size: 17px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.pips { display: inline-flex; gap: 3px; align-self: center; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); display: block; }
.pips i.used { background: #3a4570; }
.bar-stat { flex: 1 1 0; align-items: center; }
.bar { flex: 1; height: 8px; min-width: 40px; background: #0b0f1d; border-radius: 4px; overflow: hidden; display: block; }
.bar i { display: block; height: 100%; width: 50%; background: var(--ok); border-radius: 4px; transition: width .35s cubic-bezier(.3,1.4,.5,1); }
.alert .bar i { background: var(--danger); }
#statMoney.goal .val { color: var(--gold); }

.icon-btn {
  flex: none;
  width: 36px; height: 36px;
  border: 0; background: none; padding: 6px;
  cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn svg { width: 24px; height: 24px; image-rendering: pixelated; }
.icon-btn:focus-visible, .act:focus-visible, .chip:focus-visible, .choice:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* 中央の絵 */
#stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}
#shake {
  position: relative;
  aspect-ratio: 16 / 9;
  width: min(100%, calc((100cqh - 280px) * 16 / 9));
  max-height: 100%;
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--gold);
  background: #000;
}
#scene { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
#areaName {
  position: absolute; left: 8px; top: 8px;
  background: var(--navy); border: 2px solid var(--gold); border-radius: 8px;
  padding: 2px 10px; font-size: 13px;
}
#humid, #noise, #flash { position: absolute; inset: 0; pointer-events: none; }
#humid { opacity: 0; transition: opacity .8s; background:
  radial-gradient(120% 80% at 50% 120%, rgba(150,200,210,.25), transparent 60%),
  linear-gradient(rgba(120,160,170,.12), rgba(120,160,170,.12)); backdrop-filter: blur(.6px); }
#humid.on { opacity: 1; animation: humid 5s ease-in-out infinite alternate; }
@keyframes humid { from { backdrop-filter: blur(.4px); } to { backdrop-filter: blur(1.4px); } }
#noise {
  opacity: .16; mix-blend-mode: overlay;
  background-image:
    repeating-linear-gradient(0deg, rgba(0,0,0,.55) 0 1px, transparent 1px 3px);
}
#noise::after {
  content: ""; position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='64' height='64'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/></filter><rect width='64' height='64' filter='url(%23n)' opacity='.9'/></svg>");
  animation: grain .5s steps(4) infinite;
}
@keyframes grain { 0%{transform:translate(0,0)} 25%{transform:translate(-12%,8%)} 50%{transform:translate(9%,-14%)} 75%{transform:translate(-6%,-4%)} 100%{transform:translate(0,0)} }
body.no-noise #noise { display: none; }
#flash { opacity: 0; background: #fff; }

/* 吹き出し */
#bubbles, #floaters { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.bubble {
  position: absolute;
  transform: translate(-50%, -100%) scale(.6);
  transform-origin: 50% 100%;
  opacity: 0;
  background: #fffdf3; color: #1b2444;
  border-radius: 10px;
  padding: 4px 9px;
  font-size: clamp(11px, 2.2cqw, 15px);
  white-space: nowrap;
  max-width: 60cqw;
  box-shadow: 0 2px 0 rgba(0,0,0,.35);
  transition: transform .28s cubic-bezier(.3,1.6,.5,1), opacity .2s;
}
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -5px;
  border: 6px solid transparent; border-top-color: #fffdf3; border-bottom: 0;
}
.bubble.show { transform: translate(-50%, calc(-100% - 6px)) scale(1); opacity: 1; animation: bob 2.4s ease-in-out .3s infinite; }
.bubble.out { opacity: 0; transform: translate(-50%, calc(-100% - 14px)) scale(.9); }
.bubble.eerie { background: #10131f; color: #f3ecd6; }
.bubble.eerie::after { border-top-color: #10131f; }
@keyframes bob { 0%,100% { translate: 0 0; } 50% { translate: 0 -3px; } }

.floater {
  position: absolute; transform: translate(-50%, -50%);
  font-size: clamp(14px, 3cqw, 22px); color: var(--gold);
  text-shadow: 2px 2px 0 #000;
  animation: floatUp 1.1s cubic-bezier(.2,.9,.3,1) forwards;
}
.floater.bad { color: var(--danger); }
@keyframes floatUp { 0% { opacity: 0; translate: 0 10px; scale: .6; } 15% { opacity: 1; scale: 1.25; } 30% { scale: 1; } 100% { opacity: 0; translate: 0 -40px; } }

/* 操作 */
#controls { display: grid; gap: 8px; min-width: 0; }
#actions { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.act {
  position: relative;
  background: var(--navy); border: 2px solid var(--gold); border-radius: 10px;
  padding: 10px 4px; min-height: 48px;
  font-size: 14px; cursor: pointer;
  transition: transform .08s, background .15s;
}
.act:active { transform: translateY(2px) scale(.97); }
.act:disabled { opacity: .38; cursor: default; }
.act .k { display: none; }
body.kbd .act .k { display: inline-block; font-size: 10px; color: var(--dim); margin-right: 4px; }
.badge {
  position: absolute; top: -7px; right: 6px;
  min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--gold); color: var(--ink); font-size: 11px; font-weight: normal;
  display: grid; place-items: center; padding: 0 4px; box-sizing: border-box;
}
.badge:empty { display: none; }

#inventory { display: grid; gap: 6px; }
.row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-height: 32px; align-items: center; }
.row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--navy-2); border: 2px solid #3d4a7a; border-radius: 8px;
  padding: 4px 9px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.card { border-color: var(--gold); }
.chip.card.known::after { content: "裏"; font-size: 10px; color: var(--ink); background: var(--gold); border-radius: 4px; padding: 0 3px; }
.chip .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chip.member.gone { opacity: .35; text-decoration: line-through; }
.chip .mini { width: 32px; height: 5px; background: #0b0f1d; border-radius: 3px; overflow: hidden; display: inline-block; }
.chip .mini i { display: block; height: 100%; background: var(--ok); }
.chip.empty { opacity: .35; cursor: default; border-style: dashed; }
.chip.soggy { filter: saturate(.3); }
.row .tag { flex: none; font-size: 11px; color: var(--dim); width: 3.4em; white-space: nowrap; }

#log {
  list-style: none; margin: 0; padding: 6px 10px;
  background: var(--navy); border-radius: 10px; border: 2px solid #2d3864;
  height: 76px; overflow-y: auto; font-size: 13px; line-height: 1.6;
  display: flex; flex-direction: column-reverse;
}
#log li { color: var(--dim); }
#log li:first-child { color: var(--paper); }
#log li.bad { color: #f0a094; }
#log li.good { color: #f5dc7e; }

/* すりガラスのパネル */
#sheetWrap {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(5, 8, 18, .35);
  padding: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  animation: fadeIn .2s ease-out;
}
#sheet {
  position: relative;
  width: min(440px, 100%); max-height: 86%; overflow-y: auto; box-sizing: border-box;
  background: var(--glass); color: var(--glass-ink);
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
  border-radius: 18px; padding: 18px 18px 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
  animation: sheetIn .3s cubic-bezier(.2,1.3,.4,1);
}
#sheet.closing { animation: sheetOut .2s ease-in forwards; }
#sheet .close { position: absolute; right: 6px; top: 6px; }
#sheet .close svg rect { fill: var(--glass-ink); }
#sheet h2 { margin: 0 34px 8px 0; font-size: 19px; font-weight: normal; text-wrap: balance; }
#sheet p { margin: 6px 0; line-height: 1.6; }
#sheet .flavor { color: #4a5478; font-size: 14px; }
#sheet .face { border-radius: 10px; padding: 8px 10px; margin: 8px 0; background: rgba(27,36,68,.08); }
#sheet .face b { font-weight: normal; font-size: 11px; letter-spacing: .1em; color: #6a7396; display: block; }
#sheet .face.back { background: var(--navy); color: var(--paper); }
#sheet .face.back b { color: var(--gold); }
#sheet .face.unknown { color: #8a92b0; letter-spacing: .3em; }
.choices { display: grid; gap: 8px; margin-top: 12px; }
.choice {
  border: 2px solid var(--glass-ink); border-radius: 10px; background: rgba(255,255,255,.55);
  padding: 11px 12px; text-align: left; cursor: pointer; color: var(--glass-ink); font-size: 15px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.choice:active { transform: scale(.98); }
.choice.hinted::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #2f9a52; flex: none; }
.choice .note { font-size: 12px; color: #5b6488; }
.choice.mark::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px var(--glass-ink); flex: none; }
.setting { display: grid; grid-template-columns: 6em 1fr; align-items: center; gap: 10px; margin: 12px 0; }
.setting input[type=range] { width: 100%; accent-color: var(--glass-ink); }
.toggle { justify-self: start; border: 2px solid var(--glass-ink); border-radius: 999px; background: none; padding: 3px 14px; cursor: pointer; color: var(--glass-ink); }
.toggle[aria-pressed=true] { background: var(--glass-ink); color: #fff; }
.danger-btn { border: 2px solid var(--danger); color: #b8392a; background: none; border-radius: 10px; padding: 8px 12px; cursor: pointer; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes sheetIn { from { opacity: 0; transform: translateY(18px) scale(.96); } }
@keyframes sheetOut { to { opacity: 0; transform: translateY(14px) scale(.97); } }

/* 全画面（タイトル・開業・終わり） */
#screen {
  position: fixed; inset: 0; z-index: 30;
  background: radial-gradient(120% 90% at 50% 30%, #222c52, var(--ink) 70%);
  display: grid; place-items: center; text-align: center;
  padding: 24px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  overflow-y: auto;
  animation: fadeIn .35s;
}
#screen .inner { display: grid; gap: 14px; justify-items: center; width: min(560px, 100%); }
#screen .city { font-size: 15px; color: var(--dim); letter-spacing: .4em; }
#screen h1 { margin: 0; font-weight: normal; font-size: clamp(28px, 8cqw, 54px); letter-spacing: .06em; line-height: 1.15; text-shadow: 3px 3px 0 #000; }
#screen h1 .ch { display: inline-block; animation: wave 2.6s ease-in-out infinite; }
@keyframes wave { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
#screen .big { font-size: clamp(22px, 6cqw, 36px); text-shadow: 2px 2px 0 #000; min-height: 1.3em; }
#screen .typed { font-size: 16px; line-height: 1.8; min-height: 1.8em; white-space: pre-line; }
#screen .menu { display: grid; gap: 10px; width: min(300px, 100%); margin-top: 8px; }
#screen .act { font-size: 16px; padding: 12px; }
#screen .cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; }
#screen .pick {
  background: var(--navy); border: 2px solid var(--gold); border-radius: 12px; padding: 12px 10px;
  text-align: left; cursor: pointer; display: grid; gap: 8px; align-content: start;
  animation: dealIn .45s cubic-bezier(.2,1.4,.4,1) backwards;
}
#screen .pick:nth-child(2) { animation-delay: .08s; } #screen .pick:nth-child(3) { animation-delay: .16s; }
#screen .pick .nm { font-size: 15px; color: var(--gold); }
#screen .pick .sf { font-size: 13px; line-height: 1.5; }
#screen .pick .bk { font-size: 12px; color: var(--dim); line-height: 1.5; border-top: 1px dashed #3d4a7a; padding-top: 6px; }
@keyframes dealIn { from { opacity: 0; transform: translateY(40px) rotate(-6deg) scale(.8); } }
#screen .ledger { display: grid; gap: 6px; width: 100%; text-align: left; }
#screen .ledger div { display: flex; justify-content: space-between; gap: 10px; background: var(--navy); border-radius: 8px; padding: 6px 10px; font-size: 14px; animation: dealIn .4s backwards; }
#screen .ledger .lost { opacity: .4; filter: grayscale(1); text-decoration: line-through; }
#screen .ledger .kept { border: 2px solid var(--gold); }
#screen .ledger .kept span:last-child { color: var(--gold); }
#screen .rainbow { background: linear-gradient(90deg, #ff6b6b, #ffd93d, #6bff95, #6bc8ff, #c56bff, #ff6b6b); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: rb 2s linear infinite; text-shadow: none; }
@keyframes rb { to { background-position: 200% 0; } }

/* 横長で広いとき（iPad 横・PC）：絵を左、操作を右 */
@media (min-width: 560px) and (min-aspect-ratio: 5/4) {
  #stage { align-items: start; }
  #app { grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); grid-template-rows: auto minmax(0, 1fr); }
  #status { grid-column: 1 / -1; }
  #controls { align-content: start; overflow-y: auto; padding-top: 8px; }
  #actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #actions .act:last-child { grid-column: 1 / -1; }
  #log { height: auto; min-height: 120px; max-height: 40cqh; }
  #shake { width: 100%; }
}
/* 狭い画面：ステータスを2段に */
@media (max-width: 520px) {
  #status { flex-wrap: wrap; row-gap: 4px; }
  .bar-stat { flex-basis: 40%; }
  #actions { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  #actions .act { grid-column: span 2; font-size: 13px; padding: 8px 2px; }
  #actions .act:nth-child(4), #actions .act:nth-child(5) { grid-column: span 3; }
  #screen .cards { grid-template-columns: 1fr; }
  #shake { width: 100%; }
}

/* 縦長：絵の下に操作を詰め、余った高さはログに回す */
@media (max-aspect-ratio: 1/1) {
  #app { grid-template-rows: auto auto minmax(0, 1fr); }
  #stage { align-items: start; }
  #shake { width: min(100%, calc((100cqh - 450px) * 16 / 9)); min-width: 200px; }
  #controls { min-height: 0; grid-template-rows: auto auto minmax(76px, 1fr); }
  #log { height: auto; min-height: 0; }
}
