:root {
  --ink: #d8cdb4;
  --dim: #948a76;
  --line: rgba(196, 174, 134, .26);
  --panel: rgba(9, 8, 7, .6);
  --red: #b0564c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; }
body {
  display: grid; place-items: center; color: var(--ink);
  font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", "MS PMincho", serif;
}
[hidden] { display: none !important; }

#stage {
  position: relative; overflow: hidden; background: #000;
  width: min(100vw, calc(100vh * 16 / 9)); aspect-ratio: 16 / 9;
  font-size: max(8px, calc(min(100vw, 100vh * 16 / 9) / 100));
  user-select: none; -webkit-user-select: none;
}
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#view.placing { cursor: crosshair; }
#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 52%, rgba(0,0,0,0) 44%, rgba(0,0,0,.5) 80%, rgba(0,0,0,.88) 100%);
}
#grain {
  position: absolute; inset: -20%; pointer-events: none; opacity: .11; mix-blend-mode: overlay;
  background-size: 256px 256px; animation: grain .7s steps(1) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 17% { transform: translate(-4%, 3%); } 33% { transform: translate(3%, -5%); }
  50% { transform: translate(-6%, -2%); } 67% { transform: translate(5%, 6%); } 83% { transform: translate(-2%, 5%); }
}
#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .65s ease; }
#fade.on { opacity: 1; }

button {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  padding: .7em 1.2em; letter-spacing: .12em; cursor: pointer; transition: border-color .2s, background .2s, color .2s;
}
button:hover:not(:disabled) { border-color: rgba(226, 204, 160, .75); background: rgba(30, 25, 19, .78); }
button:disabled { opacity: .32; cursor: default; }
button.primary { border-color: rgba(226, 204, 160, .6); }
button.ghost { background: transparent; }
button.danger { border-color: rgba(176, 86, 76, .6); color: #e3b5a8; }
button.danger:hover:not(:disabled) { border-color: var(--red); background: rgba(52, 16, 13, .78); }

/* ───────── 育成 ───────── */
#night-num {
  position: absolute; left: 2.6em; top: 2em; font-size: 2.3em; letter-spacing: .32em;
  text-shadow: 0 0 1em #000, 0 0 .3em #000;
}
#journal {
  position: absolute; left: 2.6em; top: 8.2em; width: 25em; font-size: 1.12em; line-height: 1.9;
  text-shadow: 0 0 .7em #000, 0 0 .2em #000; pointer-events: none;
}
#journal p { margin: 0 0 .5em; color: var(--dim); transition: color 1.2s; }
#journal p.new { color: var(--ink); }
#actions {
  position: absolute; left: 50%; bottom: 2.2em; transform: translateX(-50%);
  display: flex; gap: .7em; width: max-content; max-width: 96%;
}
#actions button { display: flex; flex-direction: column; gap: .35em; padding: .8em 1.15em; text-align: left; }
#actions b { font-weight: 500; font-size: 1.08em; }
#actions i { font-style: normal; font-size: .76em; color: var(--dim); letter-spacing: .04em; }

#btn-guide2 { position: absolute; right: 2.4em; top: 2.2em; padding: .5em 1.1em; font-size: .95em; }

#hud-place {
  position: absolute; left: 50%; bottom: 2.4em; transform: translateX(-50%); width: max-content; max-width: 94%;
  display: flex; align-items: center; gap: 1.4em; padding: .9em 1.4em; background: var(--panel); border: 1px solid var(--line);
}
#hud-place p { margin: 0; font-size: 1.08em; letter-spacing: .08em; }
#hud-place #place-hint { margin-top: .45em; font-size: .84em; color: var(--dim); letter-spacing: .04em; }
#hud-place #place-hint.warn { color: #e3b5a8; }
#depths { display: flex; }
#depths small { display: block; margin-top: .2em; font-size: .7em; color: var(--dim); letter-spacing: .04em; }
#depths button { padding: .5em 1em; border-right-width: 0; }
#depths button:last-child { border-right-width: 1px; }
#depths button.on { background: rgba(120, 102, 70, .5); border-color: rgba(226, 204, 160, .7); }

/* ───────── ジオラマ ───────── */
#plate { position: absolute; left: 2.8em; bottom: 2.6em; text-shadow: 0 0 .8em #000, 0 0 .2em #000; pointer-events: none; }
#sp-no { font-size: 1em; color: var(--dim); letter-spacing: .3em; }
#sp-name { font-size: 2.7em; letter-spacing: .2em; margin: .12em 0 .3em; }
#sp-stats { display: flex; gap: 1.8em; margin: 0; font-size: 1em; }
#sp-stats div { display: flex; flex-direction: column; gap: .2em; }
#sp-stats dt { color: var(--dim); font-size: .78em; letter-spacing: .2em; }
#sp-stats dd { margin: 0; font-size: 1.2em; letter-spacing: .08em; }
#dio-actions { position: absolute; right: 2.4em; bottom: 2.4em; display: flex; flex-direction: column; gap: .55em; width: 15em; }
#dio-actions button { padding: .62em 1em; text-align: center; }
#dio-hint { position: absolute; left: 50%; top: 1.6em; transform: translateX(-50%); margin: 0; font-size: .86em; color: var(--dim); letter-spacing: .2em; text-shadow: 0 0 .6em #000; pointer-events: none; }

/* ───────── 重ね画面 ───────── */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .62); }
.title-box { text-align: center; }
.title-box h1 { margin: 0; font-size: 4.8em; font-weight: 500; letter-spacing: .34em; text-indent: .34em; text-shadow: 0 0 1.2em rgba(0,0,0,.9); }
.title-box .sub { margin: .7em 0 2em; color: var(--dim); letter-spacing: .3em; font-size: 1.1em; }
.menu { display: flex; flex-direction: column; gap: .6em; width: 22em; margin: 0 auto; font-size: 1.05em; }
.menu button { padding: .6em 1.2em; }
.menu small { display: block; margin-top: .25em; font-size: .7em; color: var(--dim); letter-spacing: .08em; }
.note { margin: 1.4em 0 0; color: var(--dim); font-size: .85em; letter-spacing: .2em; }

.shelf-box { width: 78%; max-height: 86%; display: flex; flex-direction: column; gap: 1.2em; padding: 2em 2.4em; background: rgba(12, 10, 8, .92); border: 1px solid var(--line); }
.shelf-box h2 { margin: 0; font-weight: 500; font-size: 1.7em; letter-spacing: .4em; }
#shelf-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1em; overflow-y: auto; min-height: 8em; padding-right: .4em; }
#shelf-grid .empty { grid-column: 1 / -1; color: var(--dim); letter-spacing: .14em; padding: 2em 0; }
.card { position: relative; border: 1px solid var(--line); background: #060504; cursor: pointer; transition: border-color .2s; }
.card:hover { border-color: rgba(226, 204, 160, .75); }
.card img { display: block; width: 100%; aspect-ratio: 16 / 10; object-fit: cover; }
.card .cap { padding: .5em .7em .6em; font-size: .86em; letter-spacing: .08em; }
.card .cap span { display: block; color: var(--dim); font-size: .82em; margin-top: .2em; }
.card .del { position: absolute; right: .3em; top: .3em; padding: .15em .5em; font-size: .72em; opacity: 0; }
.card:hover .del { opacity: .9; }
.code-row { display: flex; gap: .6em; }
.code-row input { flex: 1; font: inherit; font-family: Consolas, monospace; font-size: .9em; color: var(--ink); background: #060504; border: 1px solid var(--line); padding: .6em .8em; }
.shelf-box > .ghost { align-self: flex-end; }

/* ───────── X で共有 ───────── */
a.btn {
  display: inline-block; color: var(--ink); background: var(--panel); border: 1px solid var(--line); text-decoration: none;
  padding: .7em 1.2em; letter-spacing: .12em; cursor: pointer; transition: border-color .2s, background .2s;
}
a.btn.primary { border-color: rgba(226, 204, 160, .6); }
a.btn:hover { border-color: rgba(226, 204, 160, .75); background: rgba(30, 25, 19, .78); }
.x-box { width: 46em; max-width: 92%; max-height: 94%; overflow-y: auto; padding: 1.8em 2.2em; background: rgba(12, 10, 8, .95); border: 1px solid var(--line); }
.x-box h2 { margin: 0 0 .8em; font-weight: 500; font-size: 1.5em; letter-spacing: .3em; }
.x-box img { display: block; width: 100%; height: 15em; object-fit: contain; border: 1px solid var(--line); background: #060504; }
.x-box, .guide-box, #shelf-grid { scrollbar-width: thin; scrollbar-color: #4a4336 transparent; }
.x-box p { margin: 1em 0 0; font-size: 1.05em; line-height: 1.8; letter-spacing: .04em; }
.x-box dl { margin: .9em 0 0; font-size: .95em; line-height: 1.7; }
.x-box dt { color: var(--dim); font-size: .85em; letter-spacing: .16em; }
.x-box dd { margin: .2em 0 0; white-space: pre-line; word-break: break-all; }
.x-row { display: flex; justify-content: flex-end; gap: .8em; margin-top: 1.4em; }

/* ───────── 育て方 ───────── */
.guide-box {
  width: 94%; max-height: 95%; overflow-y: auto; display: grid; grid-template-columns: 21em 1fr; gap: 2.2em; align-items: start;
  padding: 1.6em 2.2em; background: rgba(12, 10, 8, .95); border: 1px solid var(--line);
}
.guide-fig svg { display: block; width: 100%; height: auto; }
.guide-fig .cap { margin: .8em 0 0; font-size: .92em; line-height: 1.75; color: var(--dim); letter-spacing: .04em; }
.guide-text h2 { margin: 0 0 .4em; font-weight: 500; font-size: 1.6em; letter-spacing: .4em; }
.guide-text .lead { margin: 0 0 1em; font-size: 1.05em; line-height: 1.75; letter-spacing: .04em; }
.guide-cols { columns: 2; column-gap: 2.4em; font-size: 1em; line-height: 1.66; letter-spacing: .03em; }
.guide-cols section { break-inside: avoid; margin: 0 0 1em; }
.guide-cols h3 { margin: 0 0 .4em; padding-bottom: .28em; font-weight: 500; font-size: 1.1em; letter-spacing: .16em; color: #ebdfc0; border-bottom: 1px solid var(--line); }
.guide-cols ul, .guide-cols ol { margin: 0; padding-left: 1.3em; }
.guide-cols li { margin-bottom: .15em; }
.guide-cols p { margin: .5em 0 0; color: var(--dim); }
.guide-cols dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: .2em 1em; }
.guide-cols dd { margin: 0; color: var(--dim); }
.guide-text > button { display: block; margin: .2em 0 0 auto; }
.fig .soil { fill: #1e1711; }
.fig .pot { fill: none; stroke: #8f5d3e; stroke-width: 3; stroke-linejoin: round; }
.fig .rim { fill: #8f5d3e; }
.fig .depth line { stroke: rgba(216, 205, 180, .3); stroke-width: 1; stroke-dasharray: 3 4; }
.fig .depth text { fill: var(--dim); font-size: 9.5px; letter-spacing: .08em; }
.fig .leaf { fill: #3f6a34; }
.fig .root { fill: none; stroke: #cdb083; stroke-linecap: round; stroke-linejoin: round; }
.fig .stone { fill: #746f66; }
.fig .bone line { stroke: #ece6d6; stroke-width: 4; stroke-linecap: round; }
.fig .bone circle { fill: #ece6d6; }
.fig .lead-line { fill: none; stroke: rgba(216, 205, 180, .55); stroke-width: 1; }
.fig .note { fill: var(--ink); font-size: 12px; letter-spacing: .1em; }

.close-x { display: none; }

#toast {
  position: absolute; left: 50%; top: 13%; transform: translate(-50%, -50%); padding: .7em 1.6em; pointer-events: none;
  background: rgba(8, 7, 6, .82); border: 1px solid var(--line); letter-spacing: .16em; opacity: 0; transition: opacity .4s;
}
#toast.on { opacity: 1; }
#fatal { position: absolute; inset: 0; display: grid; place-items: center; padding: 4em; background: #000; line-height: 2; text-align: center; letter-spacing: .1em; }

/* ───────── 小さい画面（スマホなど） ─────────
   重ね画面（育て方・標本棚・Xで共有）は、16:9 の枠の中ではなく端末の画面いっぱいに出す。
   文字は枠の大きさに連動させず読める大きさに固定し、縦にだけ動かせるようにする。 */
@media (max-width: 900px), (max-height: 520px) {
  #guide, #shelf, #xshare {
    position: fixed; inset: 0; z-index: 30; display: block; background: #080706;
    font-size: 15px; line-height: 1.5;
  }
  .guide-box, .shelf-box, .x-box {
    width: 100%; max-width: none; height: 100%; max-height: none; border: 0; background: transparent;
    padding: 3.6em 1.2em 2em; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  }
  /* 右上の閉じるボタンは、どこまで読み進めても押せる */
  .close-x {
    display: block; position: fixed; top: .5em; right: .5em; z-index: 31; width: 2.6em; height: 2.6em; padding: 0;
    font-size: 1.15em; line-height: 1; letter-spacing: 0; background: rgba(22, 19, 15, .94);
  }

  /* 育て方：図を上、説明を下に一列で */
  .guide-box { display: block; }
  .guide-fig { max-width: 19em; margin: 0 auto 1.4em; }
  .guide-fig .cap { font-size: .86em; }
  .guide-text h2 { font-size: 1.5em; }
  .guide-text .lead { font-size: 1em; }
  .guide-cols { columns: 1; font-size: 1em; line-height: 1.75; }
  .guide-cols section { margin-bottom: 1.5em; }
  .guide-cols dl { grid-template-columns: 1fr; gap: 0; }
  .guide-cols dd { margin-bottom: .55em; }
  .guide-text > button, .shelf-box > .ghost { width: 100%; margin-top: 1em; padding: .9em; }

  /* 標本棚 */
  .shelf-box { display: block; }
  .shelf-box h2 { margin-bottom: 1em; }
  #shelf-grid { grid-template-columns: repeat(2, 1fr); overflow: visible; margin-bottom: 1.2em; }
  .card .del { opacity: .9; }
  .code-row { flex-direction: column; }

  /* Xで共有 */
  .x-box img { height: auto; aspect-ratio: 16 / 9; }
  .x-row { flex-direction: column-reverse; }
  .x-row > * { width: 100%; text-align: center; padding: .9em; }
}
