:root {
  --bg: #0d0d11;
  --panel: #16161c;
  --line: #2a2a34;
  --text: #e8e8ee;
  --muted: #9a9aa8;
  --accent: #7fd8ff;
  --danger: #e05555;
}

* { box-sizing: border-box; }

/* #overlay / #inventory は display:grid を持つため、hidden 属性を明示的に勝たせる */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", -apple-system, sans-serif;
  overscroll-behavior: none;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 10px 24px;
}

/* --- 上部ステータス --- */

#topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 14px;
  padding: 4px 2px 8px;
}

#topbar h1 {
  font-size: 17px;
  margin: 0;
  letter-spacing: 0.04em;
}

#stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

#stats span { white-space: nowrap; }
#stat-hp.low { color: var(--danger); font-weight: 700; }
#stat-food.low { color: #f0c674; font-weight: 700; }

/* --- タブ --- */

#tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

#tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 16px;
  color: var(--muted);
  font-size: 14px;
}

#tabs button[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

#tabs button:hover { background: none; color: var(--text); }

/* --- アイテム一覧 --- */

.items-lead {
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--muted);
  margin: 0 0 14px;
}

.items-lead strong { color: var(--text); }

.item-group { margin-bottom: 20px; }

.item-group h3 {
  font-size: 14px;
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.item-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.item-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  padding: 3px 6px;
}

.item-table td { padding: 4px 6px; }
.item-table td.glyph { width: 1.8em; text-align: center; color: var(--accent); }
.item-table td.effect { color: var(--muted); }
.item-table tr.unknown td.true-name { color: #6a6a78; }
.item-table tr.known td.true-name { color: var(--accent); }

/* --- あそびかた --- */

#panel-help { font-size: 13.5px; line-height: 1.9; }
#panel-help p { margin: 0 0 12px; color: var(--muted); }
#panel-help strong { color: var(--text); }

.help-h {
  font-size: 15px;
  margin: 22px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.help-h:first-child { margin-top: 0; }

.help-table { border-collapse: collapse; margin-bottom: 12px; }
.help-table td { padding: 4px 14px 4px 0; vertical-align: top; }
.help-table td:last-child { color: var(--muted); }

.help-list { margin: 0 0 12px; padding-left: 1.3em; color: var(--muted); }
.help-list li { margin-bottom: 6px; }
.help-note { font-size: 12.5px; }

/* --- ランキングタブ --- */

.rank-lead { font-size: 12.5px; line-height: 1.8; color: var(--muted); margin: 0 0 14px; }

#rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#rank-table th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--line);
  padding: 5px 6px;
}

#rank-table td { padding: 6px 6px; }
#rank-table td:nth-child(2) { font-family: ui-monospace, monospace; letter-spacing: 0.1em; }
#rank-table td:nth-child(3) { text-align: right; }
#rank-table td:nth-child(4), #rank-table td:nth-child(5) { text-align: right; color: var(--muted); }
#rank-table td.time { text-align: right; color: var(--muted); font-family: ui-monospace, monospace; }
#rank-table td:nth-child(7) { color: var(--muted); }
#rank-table tr.cleared td:nth-child(2)::after { content: ' ★'; color: #f0c674; }

/* --- 画面 --- */

#stage {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #111114;
  line-height: 0;
}

#screen { display: block; }

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 10, 14, 0.86);
  line-height: 1.6;
}

.overlay-card {
  text-align: center;
  padding: 20px;
}

.overlay-card h2 { margin: 0 0 8px; font-size: 22px; }
.overlay-card p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

/* スコア内訳 */
#score-table {
  margin: 0 auto 14px;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#score-table td { padding: 3px 12px; color: var(--muted); }
#score-table td:last-child { text-align: right; color: var(--text); }

#score-table tr.total td {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
}

.overlay-hint { font-size: 12px; margin: 0 !important; }

/* 選択中のボタン(キーボード操作の現在位置)。
   非選択との差が一目で分かるよう、枠・文字色・背景をまとめて変える。 */
button.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: #2c2c38;
  box-shadow: 0 0 0 1px var(--accent) inset;
}

/* --- ログ --- */

#log {
  margin-top: 8px;
  height: 84px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.7;
}

#log p { margin: 0; color: var(--muted); }
#log p:last-child { color: var(--text); }

/* --- 操作 --- */

#controls {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

#dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
}

#dpad button {
  font-size: 17px;
  padding: 0;
}

#actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

button {
  background: #22222b;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:hover { background: #2c2c38; }
button:active { background: #363644; }

/* --- 持ち物 --- */

#inventory,
#stairs-ask,
#retire-ask,
#name-entry,
#ranking {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 12, 0.8);
  z-index: 20;
  padding: 16px;
}

/* 階段の確認 */
.ask-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  width: min(340px, 100%);
  text-align: center;
}

.ask-card h2 { margin: 0 0 8px; font-size: 17px; }
.ask-card p { margin: 0 0 16px; font-size: 14px; color: var(--muted); }

.ask-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* 選択状態は .selected だけで表す。ここで #ask-yes に常時アクセント色を当てると
   「まだ降りない」を選んでいるときも「降りる」が選択中に見えてしまう。 */

.ask-hint { margin: 14px 0 0 !important; font-size: 11.5px; }

/* --- ネーム入力(ゲーセン方式) --- */

.name-card,
.ranking-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
  width: min(400px, 100%);
}

.name-card h2,
.ranking-card h2 { margin: 0 0 6px; font-size: 17px; }

#name-rank { margin: 0 0 18px; font-size: 14px; color: var(--accent); }

#name-chars {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 18px;
}

.name-char {
  display: grid;
  place-items: center;
  width: 56px;
  height: 66px;
  font-size: 34px;
  font-family: ui-monospace, monospace;
  background: #101016;
  border: 2px solid var(--line);
  border-radius: 8px;
}

.name-char.active {
  border-color: var(--accent);
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

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

.name-hint,
.ranking-hint { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.9; }

/* --- ランキング --- */

#ranking-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#ranking-table th {
  text-align: left;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--line);
  padding: 4px 6px;
}

#ranking-table td { padding: 5px 6px; }
#ranking-table td:nth-child(2) { font-family: ui-monospace, monospace; letter-spacing: 0.1em; }
#ranking-table td:nth-child(3) { text-align: right; }
#ranking-table td:nth-child(4),
#ranking-table td:nth-child(5) { text-align: right; color: var(--muted); }
#ranking-table td.time { text-align: right; color: var(--muted); font-family: ui-monospace, monospace; }

#ranking-table tr.me td { color: var(--accent); font-weight: 700; }
#ranking-table tr.cleared td:nth-child(2)::after { content: ' ★'; color: #f0c674; }

.inv-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  width: min(720px, 100%);
  max-height: 85vh;
  overflow-y: auto;
}

/* 一覧と行動メニューを横並びにする。縦に積むと一覧が長いときに
   メニューが画面外へ押し出されてスクロールが要るため。 */
.inv-columns {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.inv-columns #inv-list { flex: 1; min-width: 0; }

.inv-card h2 { margin: 0 0 10px; font-size: 17px; }
.inv-equip { margin: 0 0 12px; font-size: 13px; color: var(--accent); }

#inv-list { list-style: none; margin: 0 0 12px; padding: 0; }

#inv-list li { margin-bottom: 6px; }

#inv-list button {
  width: 100%;
  text-align: left;
  font-size: 14px;
}

#inv-list button.equipped {
  border-color: var(--accent);
  color: var(--accent);
}

/* 足元のアイテム(持ち物ではなく床にあるもの)は破線で区別する */
#inv-list button.floor-item {
  border-style: dashed;
  color: var(--muted);
}
#inv-list button.floor-item.selected { color: inherit; }

.inv-empty { color: var(--muted); font-size: 14px; }

.offline-note td {
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  padding-bottom: 6px;
}
.inv-count { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* 行動メニュー(持ち物一覧の中に開く) */
#item-action {
  width: 190px;
  flex: none;
  border-left: 1px solid var(--line);
  padding-left: 16px;
  position: sticky;
  top: 0;
}

#action-target {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--accent);
}

#action-list { list-style: none; margin: 0; padding: 0; }
#action-list li { margin-bottom: 6px; }

#action-list button {
  width: 100%;
  text-align: left;
  font-size: 14px;
}

.inv-hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.8; }

.inv-buttons { display: flex; gap: 8px; }
.inv-buttons button { flex: 1; }

/* --- 説明 --- */

#help {
  margin-top: 16px;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--muted);
}

#help p { margin: 0 0 4px; }

kbd {
  background: #22222b;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
}

#seed-line { font-family: ui-monospace, monospace; font-size: 11.5px; }

@media (max-width: 560px) {
  .inv-columns { flex-direction: column; }
  #item-action {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 12px;
    position: static;
  }
  #topbar h1 { font-size: 15px; }
  #dpad { grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 50px); }
  #log { height: 70px; }
}
