/* 深海ダイブ 共通スタイル */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
body { margin: 0; font-size: 14px; }
img { max-width: 100%; }
:root {
  color-scheme: dark;
  --abyss: #030a12;
  --panel: rgba(4, 16, 26, 0.74);
  --line: rgba(140, 210, 230, 0.16);
  --ink: #d9eef2;
  --muted: #7896a1;
  --sonar: #8ee6f2;
  --sonar-dim: rgba(142, 230, 242, 0.14);
  --serif: "Shippori Mincho B1", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --sans: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Consolas", monospace;
}
html, body { height: 100%; }
[hidden] { display: none !important; }
body { background: var(--abyss); color: var(--ink); font-family: var(--sans); overflow: hidden; }
#scene { position: fixed; inset: 0; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pin { position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 12px; letter-spacing: .05em;
  text-shadow: 0 0 4px #000, 0 0 2px #000; will-change: transform; }
.pin::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--sonar);
  margin-right: 6px; vertical-align: 1px; box-shadow: 0 0 8px var(--sonar); }
.pin.area { font-family: var(--serif); font-size: 14px; color: rgba(217, 238, 242, .75); letter-spacing: .2em; }
.pin.area::before { display: none; }
.hud { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

/* 計器パネル */
#panel { top: calc(16px + env(safe-area-inset-top, 0px)); left: 16px; width: 312px; padding: 16px 18px; display: grid; gap: 12px;
  max-height: calc(100% - 120px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); overflow-y: auto; }
.back { font-size: 12px; color: var(--sonar); text-decoration: none; letter-spacing: .06em; }
.back:hover { text-decoration: underline; }
.brand { font-size: 11px; letter-spacing: .18em; color: var(--muted); }
#depth { font-family: var(--mono); font-size: 40px; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
#depth small { font-size: 16px; color: var(--muted); margin-left: 4px; }
#zone { display: grid; gap: 4px; }
#zone h2 { margin: 0; font-family: var(--serif); font-weight: 800; font-size: 22px; letter-spacing: .06em; }
#zone h2 small { font-family: var(--mono); font-weight: 400; font-size: 11px; color: var(--muted); letter-spacing: .04em; margin-left: 8px; }
#zone p { margin: 0; font-size: 12.5px; line-height: 1.7; color: #b3cad1; }
#gauges { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 12px; }
#gauges dt { color: var(--muted); }
#gauges dd { margin: 0; font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.sub { font-size: 11px; letter-spacing: .14em; color: var(--sonar); }
#life { display: grid; gap: 8px; }
#life ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
#life li { display: grid; gap: 2px; padding-left: 10px; border-left: 2px solid var(--sonar-dim); }
#life b { font-size: 13px; font-weight: 700; }
#life span { font-size: 12px; line-height: 1.6; color: #a9c1c8; }
#life .none { font-size: 12px; color: var(--muted); }

/* 深度ルーラー */
#ruler { top: calc(16px + env(safe-area-inset-top, 0px)); right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); width: 188px;
  padding: 0; overflow: hidden; cursor: ns-resize; touch-action: none; }
#ruler .band { position: absolute; right: 0; width: 26px; }
#ruler .bandLbl { position: absolute; right: 32px; font-family: var(--serif); font-size: 11px; color: var(--muted); transform: translateY(4px); }
#ruler .tick { position: absolute; right: 0; width: 34px; border-top: 1px solid rgba(217, 238, 242, .2); }
#ruler .tick span { position: absolute; right: 38px; top: -8px; font-family: var(--mono); font-size: 10px; color: var(--muted); }
#ruler .mark { position: absolute; left: 10px; right: 30px; border-top: 1px dashed rgba(243, 214, 160, .45); }
#ruler .mark span { position: absolute; left: 0; top: -15px; font-size: 10px; color: #e6cfa3; white-space: nowrap; }
#now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--sonar); box-shadow: 0 0 10px var(--sonar); pointer-events: none; }
#now span { position: absolute; left: 8px; top: 2px; font-family: var(--mono); font-size: 11px; color: var(--sonar); }
#floor { position: absolute; left: 0; right: 0; bottom: 0; background: repeating-linear-gradient(135deg, rgba(120,110,95,.35) 0 4px, transparent 4px 8px); }

/* 操作バー */
#controls { left: 50%; transform: translateX(calc(-50% - 110px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; max-width: calc(100% - 260px); }
.btn { all: unset; cursor: pointer; font-size: 12px; padding: 7px 11px; border-radius: 6px; border: 1px solid var(--line); white-space: nowrap; }
.btn:hover { border-color: var(--sonar); }
.btn[hidden] { display: none; }
.btn[aria-pressed="true"] { background: var(--sonar-dim); border-color: var(--sonar); color: var(--sonar); }
.btn.primary { background: var(--sonar); color: #02202a; border-color: var(--sonar); font-weight: 700; }
.btn:focus-visible { outline: 2px solid var(--sonar); outline-offset: 2px; }
.grp { display: flex; gap: 4px; }
.sep { width: 1px; height: 22px; background: var(--line); }
#toast { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); transform: translate(calc(-50% + 60px), -8px); opacity: 0;
  background: var(--panel); border: 1px solid var(--sonar); color: var(--ink); padding: 10px 16px; border-radius: 8px; font-size: 13px;
  transition: opacity .4s, transform .4s; pointer-events: none; max-width: min(460px, calc(100% - 32px)); text-align: center; }
#toast.show { opacity: 1; transform: translate(calc(-50% + 60px), 0); }
#hint { position: fixed; left: 16px; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); font-size: 11px; color: var(--muted); max-width: 300px; }

#splash { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .9s ease-out;
  background: radial-gradient(ellipse at 50% 30%, rgba(210, 242, 250, .55), rgba(60, 160, 190, .35) 60%, rgba(20, 90, 120, .5)); }
#splash.show { opacity: 1; transition: opacity .12s; }

/* 表示の切り替え（3D ⇄ ダイブマップ） */
#tabs { top: calc(16px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(calc(-50% + 60px)); display: flex; gap: 2px; padding: 3px; z-index: 6; }
#tabs .tab { all: unset; cursor: pointer; font-size: 12px; padding: 6px 14px; border-radius: 7px; color: var(--muted); letter-spacing: .05em; }
#tabs .tab[aria-selected="true"] { background: var(--sonar-dim); color: var(--sonar); }
#tabs .tab:focus-visible { outline: 2px solid var(--sonar); }
/* ダイブマップ（画面いっぱい） */
#divemap { position: fixed; inset: 0; z-index: 5; background: #061420; }
#dmap { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#divemap .zoom { position: absolute; right: 16px; top: calc(16px + env(safe-area-inset-top, 0px)); display: grid; gap: 6px; }
#divemap .zoom .btn { text-align: center; background: var(--panel); min-width: 22px; }
#dmapCard { left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); padding: 12px 16px; display: grid; gap: 6px; justify-items: center; min-width: min(360px, calc(100% - 32px)); text-align: center; }
#dmapWhere { font-family: var(--mono); font-size: 12px; color: var(--ink); }
#dmapDepth { font-size: 13px; color: #b3cad1; min-height: 1em; }
#dmapGo[disabled] { opacity: .4; cursor: default; }
.maplbl { font-size: 10px; color: var(--muted); letter-spacing: .06em; }
#pad { left: 16px; bottom: calc(52px + env(safe-area-inset-bottom, 0px)); padding: 8px; display: grid; grid-template-columns: repeat(3, 48px); gap: 6px; }
#pad .btn { text-align: center; padding: 8px 0; user-select: none; -webkit-user-select: none; touch-action: none; }
#pad .btn.on { background: var(--sonar-dim); border-color: var(--sonar); color: var(--sonar); }
#panel.dive { max-height: calc(100% - 220px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }

/* 宝探し */
.btn.gold { border-color: rgba(243, 200, 110, .6); color: #f3cf86; }
.btn.gold[aria-expanded="true"] { background: rgba(243, 200, 110, .15); }
#quest { right: 220px; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); width: 320px; padding: 14px 16px; display: grid; gap: 10px; }
#quest header { display: flex; align-items: center; justify-content: space-between; }
#quest h3, #found h3 { margin: 0; font-family: var(--serif); font-size: 18px; letter-spacing: .08em; color: #f3cf86; }
#quest p, #found p { margin: 0; font-size: 12.5px; line-height: 1.7; color: #b3cad1; }
#quest b { color: #f3cf86; font-weight: 500; }
#questStatus { font-size: 12px; font-family: var(--mono); color: var(--ink); }
#hintList { margin: 6px 0 8px; padding-left: 18px; display: grid; gap: 4px; font-size: 12.5px; line-height: 1.6; }
#hintList:empty { display: none; }
#echo { left: 50%; top: calc(76px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); padding: 8px 14px; font-size: 13px;
  border-color: rgba(243, 200, 110, .7); color: #f3cf86; font-family: var(--mono); white-space: nowrap; }
#soundAsk { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(400px, calc(100% - 32px)); padding: 20px 22px;
  display: grid; gap: 12px; z-index: 10; box-shadow: 0 0 60px rgba(0, 0, 0, .5); }
#soundAsk h3 { margin: 0; font-family: var(--serif); font-size: 19px; letter-spacing: .06em; }
#soundAsk p { margin: 0; font-size: 13px; line-height: 1.7; color: #b3cad1; }
#soundAsk .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#found { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px)); padding: 20px 22px; display: grid; gap: 12px;
  border-color: rgba(243, 200, 110, .8); box-shadow: 0 0 60px rgba(243, 200, 110, .25); }
#found textarea { width: 100%; box-sizing: border-box; resize: none; background: rgba(0,0,0,.3); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px; font: 12px/1.6 var(--sans); }
#found .row { display: flex; gap: 8px; justify-content: flex-end; }

/* 生き物の表示（プレビュー中だけ） */
#lifeSel { left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom, 0px)); width: min(420px, calc(100% - 32px));
  max-height: calc(100% - 200px); overflow-y: auto; padding: 14px 16px; display: grid; gap: 10px; z-index: 5; }
#lifeSel header { display: flex; align-items: center; justify-content: space-between; }
#lifeSel h3 { margin: 0; font-family: var(--serif); font-size: 16px; letter-spacing: .06em; }
#lifeSel p { margin: 0; font-size: 12px; line-height: 1.7; color: #b3cad1; }
#lifeSel .row { display: flex; gap: 8px; }
#lifeSel ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#lifeSel label { display: flex; align-items: baseline; gap: 8px; font-size: 13px; cursor: pointer; padding: 4px 2px; }
#lifeSel label span { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }
#lifeSel input { accent-color: var(--sonar); }

/* 図鑑と実績 */
#zukanBtn { border-color: rgba(142, 230, 242, .45); }
#zukanBtn.new::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: #f3cf86; vertical-align: 2px; }
/* 図鑑: 上の「3D / ダイブマップ」と、下の操作ボタンの間に置く（ボタンを隠さない）。--zk-bottom は zukan.js が操作ボタンの高さから決める。
   見出し（閉じるボタン）とタブは動かさず、一覧だけをスクロールする */
#zukan { left: 50%; top: 64px; bottom: var(--zk-bottom, 160px); transform: translateX(-50%); width: min(760px, calc(100% - 32px)); max-height: none;
  overflow: hidden; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; z-index: 6; }
#zukan > header, #zukan > .tabs { flex: none; }
#zkLife, #zkAchv { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#zukan header { display: flex; align-items: baseline; gap: 12px; }
#zukan h3 { margin: 0; font-family: var(--serif); font-size: 20px; letter-spacing: .08em; }
#zkCount { font-family: var(--mono); font-size: 12px; color: var(--muted); }
#zkClose { margin-left: auto; }
#zukan .tabs { display: flex; gap: 6px; }
#zukan .tabs .btn[aria-selected="true"] { background: var(--sonar-dim); border-color: var(--sonar); color: var(--sonar); }
#zukan .lead, #zukan .none { margin: 0; font-size: 12px; color: #b3cad1; line-height: 1.7; }
#zukan .cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
#zukan .cards li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 10px; display: grid; gap: 4px; align-content: start; background: rgba(0, 0, 0, .18); }
#zukan .cards li.got { border-color: rgba(142, 230, 242, .35); }
#zukan .cards img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; border-radius: 4px; background: radial-gradient(ellipse at 50% 60%, rgba(40, 90, 110, .45), rgba(4, 16, 26, .2)); }
#zukan .cards b { font-family: var(--serif); font-size: 15px; letter-spacing: .04em; }
#zukan .cards .unk b { color: var(--muted); letter-spacing: .3em; }
#zukan .cards i { font-family: var(--mono); font-style: normal; font-size: 10.5px; color: var(--muted); }
#zukan .cards p { margin: 0; font-size: 11.5px; line-height: 1.6; color: #b3cad1; }
#zukan .cards small { font-family: var(--mono); font-size: 10.5px; color: var(--sonar); }
#zukan .achv { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#zukan .achv li { display: grid; grid-template-columns: 22px 1fr auto; column-gap: 8px; align-items: baseline; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
#zukan .achv li .mark { grid-row: span 2; color: var(--muted); font-size: 15px; }
#zukan .achv li.got { border-color: rgba(243, 200, 110, .45); }
#zukan .achv li.got .mark, #zukan .achv li.got b { color: #f3cf86; }
#zukan .achv b { font-size: 14px; font-weight: 500; }
#zukan .achv p { grid-column: 2; margin: 0; font-size: 11.5px; color: #b3cad1; line-height: 1.6; }
#zukan .achv small { grid-column: 3; grid-row: 1; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
#zukan .cards .shot { position: relative; }
#zukan .cards .shot::after { content: "写真"; position: absolute; left: 6px; top: 6px; font-size: 10px; letter-spacing: .1em; padding: 1px 6px; border-radius: 4px; background: rgba(3, 10, 18, .75); color: var(--sonar); }
#zukan .cards .shot img { object-fit: cover; }
/* 高度計（海底まで） */
#alt { left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom, 0px)); padding: 6px 14px; display: flex; align-items: baseline; gap: 10px; }
#alt span { font-size: 11px; letter-spacing: .12em; color: var(--muted); }
#alt b { font-family: var(--mono); font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--sonar); }
#alt.warn { border-color: rgba(243, 200, 110, .7); }
#alt.warn b { color: #f3cf86; }
#alt[hidden] { display: none; }
/* 撮影の光 */
#flash { position: fixed; inset: 0; pointer-events: none; background: #fff; opacity: 0; transition: opacity .5s ease-out; z-index: 8; }
#flash.on { opacity: .75; transition: none; }
/* 図鑑に登録・実績解除の知らせ */
#award { position: fixed; left: 50%; top: calc(76px + env(safe-area-inset-top, 0px)); transform: translate(calc(-50% + 60px), -10px); opacity: 0; pointer-events: none;
  display: grid; gap: 2px; justify-items: center; text-align: center; max-width: min(460px, calc(100% - 32px)); padding: 12px 22px 13px;
  background: var(--panel); border: 1px solid var(--sonar); border-radius: 10px; backdrop-filter: blur(6px); transition: opacity .4s, transform .4s; z-index: 7; }
#award.show { opacity: 1; transform: translate(calc(-50% + 60px), 0); }
#award small { font-size: 10.5px; letter-spacing: .3em; color: var(--sonar); }
#award b { font-family: var(--serif); font-size: 20px; letter-spacing: .08em; }
#award span { font-size: 12px; color: #b3cad1; line-height: 1.6; }
#award.achv { border-color: rgba(243, 200, 110, .8); }
#award.achv small, #award.achv b { color: #f3cf86; }

#src { font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
#src summary { cursor: pointer; letter-spacing: .1em; color: var(--sonar); }
#src ul { margin: 8px 0 0; padding-left: 16px; display: grid; gap: 6px; line-height: 1.6; }
#src b { display: block; color: var(--ink); font-weight: 500; }
#src a { color: var(--sonar); }
.vol { align-items: center; }
#vol { width: 72px; accent-color: var(--sonar); }

/* スマホ・小さい画面用の開閉ボタン（広い画面では出さない） */
#panelToggle, #moreBtn { display: none; }
.btn.mini { padding: 6px 10px; font-size: 12px; }

/* スマホ（縦）と、高さの低い画面（スマホ横向き）: 景色が主役になるよう、普段は最小限だけ表示 */
@media (max-width: 760px), (max-height: 520px) {
  #hint, .sep { display: none; }
  /* 下の操作ボタンの高さ（折り返しで 1〜3 段に変わる）は ui.js が測り、--ctl-top（ボタンの上端から画面の下まで）と --stack-top（移動パッドの上端まで）に入れる */
  #tabs { top: auto; bottom: calc(var(--stack-top, 118px) + 6px); left: 12px; transform: none; }
  #divemap .zoom { top: auto; bottom: calc(150px + env(safe-area-inset-bottom, 0px)); right: 12px; }
  #dmapCard { bottom: calc(160px + env(safe-area-inset-bottom, 0px)); }
  /* 計器パネル: 普段は「深さ＋層の名前」の1行。「詳細」で開く */
  #panel { top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; right: 74px; width: auto; padding: 8px 12px; gap: 8px;
    grid-template-columns: auto 1fr auto; align-items: center; max-height: 64%; }
  #panel > * { grid-column: 1 / -1; }
  #panel #depth { grid-column: 1; font-size: 24px; }
  #panel #zone { grid-column: 2; min-width: 0; }
  #panel #panelToggle { grid-column: 3; display: inline-block; }
  #zone h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #zone h2 small, #zone p { display: none; }
  #panel:not(.open) > :not(#depth):not(#zone):not(#panelToggle) { display: none; }
  #panel.open #zone { grid-column: 1 / -1; }
  #panel.open #zone p { display: block; }
  #panel.open { max-height: 45%; }
  /* 深度ルーラー: 細く、ボタンと重ならない高さに */
  #ruler { top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; width: 54px; bottom: calc(var(--ctl-top, 76px) + 6px); }
  #ruler .bandLbl, #ruler .mark span { display: none; }
  #ruler .mark { left: 2px; right: 14px; }
  #ruler .band { width: 12px; }
  #ruler .tick { width: 16px; }
  #ruler .tick span { right: 18px; top: -7px; font-size: 9px; color: #a9c1c8; }
  /* 現在の深さ: 線の上に小さな札として出す（km 表記） */
  #now span { left: 2px; top: -16px; font-size: 10px; padding: 0 3px; border-radius: 3px; background: rgba(3, 10, 18, .85); }
  /* 操作: 普段は1段。「設定」で残りを開く */
  #controls { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); transform: none; max-width: none; padding: 8px; gap: 6px; }
  #controls #moreBtn { display: inline-block; }
  #controls:not(.open) .more { display: none; }
  #controls .btn { padding: 7px 9px; }
  /* 移動パッド: 操作ボタンのすぐ上、左下 */
  #pad { left: 12px; bottom: calc(var(--ctl-top, 76px) + 6px); padding: 6px; gap: 5px; grid-template-columns: repeat(3, 42px); }
  #pad .btn { padding: 7px 0; }
  #toast, #toast.show { top: calc(64px + env(safe-area-inset-top, 0px)); transform: translate(-50%, 0); font-size: 12px; }
  #quest { left: 12px; right: 12px; width: auto; bottom: calc(var(--ctl-top, 76px) + 6px); }
  #lifeSel { left: 12px; right: 12px; width: auto; transform: none; bottom: calc(var(--ctl-top, 76px) + 6px); max-height: 60%; }
  #alt { left: auto; right: 74px; transform: none; bottom: calc(var(--ctl-top, 76px) + 6px); padding: 4px 10px; }   /* 移動パッド（左下）と重ならないよう、右へ */
  #alt b { font-size: 16px; }
  #zukan { left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top, 0px)); bottom: var(--zk-bottom, calc(76px + env(safe-area-inset-bottom, 0px))); width: auto; max-height: none; transform: none; padding: 12px; }
  #zukan .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  #award, #award.show { top: calc(112px + env(safe-area-inset-top, 0px)); transform: translate(-50%, 0); padding: 10px 16px; }
  #award b { font-size: 17px; }
  #echo { top: auto; bottom: calc(190px + env(safe-area-inset-bottom, 0px)); white-space: normal; }
}
@media (prefers-reduced-motion: reduce) { #toast, #splash, #award { transition: none; } }
