/* YoursCraft — 画面まわり。マイクラの UI（影つき文字・石のボタン・土の背景）に寄せている */
:root {
  --panel: rgba(16, 16, 20, 0.86);
  --line: #0f0f12;
  --btn: #8b8b8b;
  --btn-top: #b9b9b9;
  --btn-hi: #a7c6ff;
  --text: #ffffff;
  --muted: #a9a9a9;
  --gold: #ffd75e;
  --slot: rgba(139, 139, 139, 0.55);
  --hud: 1;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #000;
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, -apple-system, sans-serif;
  font-weight: 700;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; }

canvas#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.shadow { text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6); }

/* ---------- 画面の暗幕 ---------- */
#water-tint, #vignette, #lava-tint {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.25s;
}
#water-tint { background: linear-gradient(rgba(28, 80, 170, 0.55), rgba(16, 50, 120, 0.7)); }
#lava-tint { background: linear-gradient(rgba(190, 70, 10, 0.72), rgba(120, 30, 0, 0.8)); }
#vignette { background: radial-gradient(circle at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.38) 100%); opacity: 1; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud[hidden] { display: none; }

/* 指で触ったところに出る波紋 */
#ripples { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.ripple {
  position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px;
  border: 3px solid rgba(255, 255, 255, 0.85); border-radius: 50%;
  animation: ripple-out 0.4s ease-out forwards;
}
@keyframes ripple-out {
  from { transform: scale(0.35); opacity: 0.9; }
  to { transform: scale(1.15); opacity: 0; }
}

#crosshair {
  position: absolute; left: 50%; top: 50%; width: 22px; height: 22px;
  transform: translate(-50%, -50%); mix-blend-mode: difference;
}
#crosshair::before, #crosshair::after {
  content: ""; position: absolute; background: #fff;
}
#crosshair::before { left: 9px; top: 0; width: 4px; height: 22px; }
#crosshair::after { top: 9px; left: 0; height: 4px; width: 22px; }

/* ホットバー */
#hotbar {
  position: absolute; left: 50%; bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; gap: 0;
  padding: 4px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.42);
  border: 2px solid rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}
.slot {
  position: relative; width: 54px; height: 54px; margin: 0;
  background: var(--slot);
  border: 2px solid;
  border-color: #5a5a5a #d5d5d5 #d5d5d5 #5a5a5a;
  display: flex; align-items: center; justify-content: center;
}
.slot canvas { width: 40px; height: 40px; image-rendering: pixelated; pointer-events: none; }
.slot.sel {
  outline: 3px solid #fff; outline-offset: -1px; z-index: 2;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.6), 0 0 12px rgba(255, 255, 255, 0.35);
}
.slot .num {
  position: absolute; right: 2px; bottom: 0; font-size: 11px; color: #ddd;
  text-shadow: 1px 1px 0 #000;
}
@media (max-width: 720px) { .slot { width: 44px; height: 44px; } .slot canvas { width: 32px; height: 32px; } }

/* 持っているブロックの名前（マイクラ同様、切り替えたときだけ出る） */
#itemname {
  position: absolute; left: 50%; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 76px);
  transform: translateX(-50%);
  font-size: 17px; opacity: 0; transition: opacity 0.4s;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.7); white-space: nowrap;
}
@media (max-width: 720px) { #itemname { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 64px); font-size: 15px; } }

/* デバッグ表示（F3 相当） */
#debug {
  position: absolute; left: 8px; top: 8px; font-size: 13px; line-height: 1.5;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 400;
  background: rgba(0, 0, 0, 0.42); padding: 6px 9px; border-radius: 3px;
  white-space: pre; pointer-events: none;
}
#debug[hidden] { display: none; }

/* 右上のボタン群 */
#topright { position: absolute; right: 10px; top: 10px; display: flex; gap: 8px; pointer-events: auto; }

.tbtn {
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
  background: rgba(30, 30, 34, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.28);
  color: #fff; font-size: 20px; border-radius: 8px;
  width: 46px; height: 46px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.tbtn:active, .tbtn.on { background: rgba(255, 255, 255, 0.32); }
.tbtn.big { width: 68px; height: 68px; font-size: 26px; border-radius: 50%; }
.tbtn .lbl { font-size: 10px; opacity: 0.85; }

/* 左下：バーチャルスティック */
#stick {
  position: absolute; left: 22px; bottom: calc(22px + env(safe-area-inset-bottom));
  width: 150px; height: 150px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.2);
  pointer-events: auto;
}
#stick::after {
  content: ""; position: absolute; inset: 32%; border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.14);
}
#knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.5);
}
/* 右下：ジャンプ・上下・飛行 */
#rightpad {
  position: absolute; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom));
  pointer-events: auto;
  display: grid; grid-template-columns: 56px 68px; grid-template-rows: 56px 68px;
  gap: 10px; align-items: center; justify-items: center;
}
#btn-fly { grid-column: 1; grid-row: 1; }
#btn-up { grid-column: 2; grid-row: 1; }
#btn-down { grid-column: 1; grid-row: 2; }
#btn-jump { grid-column: 2; grid-row: 2; }

/* 右手の「こわす／おく」ボタン。画面のタップ・長押しでも同じことができるが、
   ボタンがあるほうが確実（マイクラ統合版のタッチ操作に近い） */
#actionpad {
  position: absolute; right: calc(20px + 150px); bottom: calc(28px + env(safe-area-inset-bottom));
  pointer-events: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.tbtn.act {
  width: 62px; height: 62px; border-radius: 14px;
  flex-direction: column; gap: 1px; line-height: 1;
}
.tbtn.act .ico { font-size: 22px; }
.tbtn.act .lbl { font-size: 10.5px; }
@media (max-width: 820px) {
  #actionpad { right: calc(16px + 132px); gap: 9px; }
  .tbtn.act { width: 54px; height: 54px; }
}

/* 縦持ちのときは横幅が足りないので、ホットバーを操作ボタンの上へ逃がす */
@media (orientation: portrait) {
  #hotbar { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 210px); }
  #itemname { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 282px); }
  #actionpad {
    right: 16px; bottom: calc(175px + env(safe-area-inset-bottom));
    flex-direction: row; gap: 9px;
  }
}

#mobile-only { display: contents; }
body.desktop #stick, body.desktop #rightpad, body.desktop #actionpad { display: none; }

/* 操作ヒント */
#hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  max-width: min(560px, 62vw);
  font-size: 13px; color: #e8e8e8; background: rgba(0, 0, 0, 0.42);
  padding: 5px 12px; border-radius: 20px; opacity: 0; transition: opacity 0.5s;
  text-align: center; max-width: 88vw;
}

/* セーブ通知（マイクラの「ワールドを保存中」風） */
#toast {
  position: absolute; right: 12px; top: 68px;
  font-size: 13px; background: rgba(0, 0, 0, 0.5); padding: 6px 12px;
  border-radius: 3px; opacity: 0; transition: opacity 0.4s;
}
#toast.show { opacity: 1; }

/* ---------- メニュー ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  padding: 24px; z-index: 10;
}
.screen[hidden] { display: none; }
.screen.dim { background: rgba(0, 0, 0, 0.62); }
.screen.dirt {
  background-color: #6b4c33;
  background-repeat: repeat; background-size: 64px 64px;
  image-rendering: pixelated;
}
.screen.dirt::before {
  content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55);
}
.screen > * { position: relative; z-index: 1; }

.btn {
  pointer-events: auto; cursor: pointer;
  width: min(340px, 82vw); padding: 13px 18px;
  font-size: 17px; font-weight: 700; color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
  background: linear-gradient(180deg, #a2a2a2 0%, #8b8b8b 48%, #6f6f6f 100%);
  border: 2px solid;
  border-color: #cfcfcf #3d3d3d #3d3d3d #cfcfcf;
  border-radius: 2px;
  letter-spacing: 0.04em;
}
.btn:hover, .btn:focus-visible { background: linear-gradient(180deg, #b9c9e6 0%, #8fa4c9 48%, #6f80a3 100%); outline: none; }
.btn:active { transform: translateY(1px); }
.btn.small { width: min(165px, 40vw); font-size: 15px; padding: 10px 12px; }
.btn.wide { width: min(420px, 88vw); }
.btn[disabled] { opacity: 0.5; }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

h1.logo-wrap { margin: 0 0 6px; }
#logo { image-rendering: pixelated; width: min(560px, 88vw); height: auto; display: block; }
.tagline { margin: -4px 0 10px; font-size: 14px; color: #ffd75e; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6); }
.credit { position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: #ddd; text-shadow: 1px 1px 0 #000; z-index: 2; }
.credit a { color: #9fc7ff; }
.version { position: absolute; right: 10px; bottom: 8px; font-size: 12px; color: #ddd; text-shadow: 1px 1px 0 #000; z-index: 2; }

.panel {
  pointer-events: auto;
  background: var(--panel); border: 2px solid #000;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
  border-radius: 4px; padding: 16px 18px;
  width: min(560px, 94vw); max-height: 86vh; overflow: auto;
}
/* パネルの中身が長いとき、とじるボタンは下に貼りつける */
.panel > .btnrow:last-child {
  position: sticky; bottom: -16px; margin-top: 14px;
  padding: 10px 0 4px; background: linear-gradient(rgba(16,16,20,0), rgba(16,16,20,0.96) 40%);
}
.panel h2 { margin: 0 0 12px; font-size: 19px; text-align: center; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6); }
.panel h3 { margin: 16px 0 6px; font-size: 14px; color: var(--gold); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; }
.row label { flex: 0 0 auto; }
.row .val { color: var(--gold); min-width: 58px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { flex: 1 1 auto; accent-color: #9fc7ff; height: 24px; }
input[type=text] {
  flex: 1 1 auto; background: #111; color: #fff; border: 2px solid #555;
  padding: 8px 10px; font-size: 15px; font-family: inherit; border-radius: 2px; min-width: 0;
}
.toggle {
  pointer-events: auto; cursor: pointer; min-width: 96px; text-align: center;
  padding: 7px 12px; font-size: 14px; border: 2px solid;
  border-color: #cfcfcf #3d3d3d #3d3d3d #cfcfcf;
  background: linear-gradient(180deg, #9a9a9a, #6f6f6f); color: #fff;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.6);
}
.toggle.on { background: linear-gradient(180deg, #7ec87e, #3f8f3f); }
.help-table { width: 100%; font-size: 13.5px; font-weight: 400; border-collapse: collapse; }
.help-table td { padding: 5px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.12); vertical-align: top; }
.help-table td:first-child { color: var(--gold); white-space: nowrap; width: 38%; font-weight: 700; }

/* ---------- インベントリ ---------- */
#inventory { background: rgba(0, 0, 0, 0.55); }
.inv-panel { width: min(660px, 96vw); }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tab {
  pointer-events: auto; cursor: pointer; display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; font-size: 14px; color: #fff;
  background: linear-gradient(180deg, #6d6d6d, #4a4a4a);
  border: 2px solid; border-color: #9b9b9b #2d2d2d #2d2d2d #9b9b9b;
}
.tab.on { background: linear-gradient(180deg, #c9c9c9, #9a9a9a); color: #111; text-shadow: none; }
.tab canvas { width: 22px; height: 22px; image-rendering: pixelated; }
.inv-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 4px; max-height: min(46vh, 360px); overflow-y: auto; padding: 4px;
  background: rgba(0, 0, 0, 0.35); border: 2px solid #000;
}
.inv-grid .slot { width: 100%; aspect-ratio: 1; height: auto; cursor: pointer; }
.inv-hotbar { display: flex; gap: 0; justify-content: center; margin-top: 12px; }
.inv-note { font-size: 12.5px; color: var(--muted); text-align: center; margin-top: 8px; font-weight: 400; }

/* ---------- 読み込み中 ---------- */
/* タイトルは世界の風景を背景にする（マイクラのパノラマ画面と同じ狙い） */
.screen.pano { background: rgba(0, 0, 0, 0.34); }
.screen.pano #logo { filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.75)); }
.screen.pano .btn { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45); }

#loading { background: #0b0f18; }
.bar {
  width: min(420px, 80vw); height: 16px; border: 2px solid #fff; padding: 2px;
}
.bar > div { height: 100%; width: 0%; background: #7ec87e; transition: width 0.2s; }
.loading-text { font-size: 15px; }

/* ねむるときの暗転（ベッド） */
#sleep-fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .85s ease;
  z-index: 60;
}
#sleep-fade.on { opacity: 1; }
