:root {
  color-scheme: dark;
  --ink: #f8fafc;
  --muted: rgba(248, 250, 252, .72);
  --panel: rgba(9, 14, 24, .76);
  --line: rgba(255, 219, 82, .95);
  --shadow: rgba(64, 225, 255, .9);
  --danger: #ff5b73;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #090e18;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* なぞって遊ぶゲームなので、長押しの選択・コールアウトは全部殺す */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
}

.game-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 210, 47, .16), transparent 28%),
    radial-gradient(circle at 78% 18%, rgba(50, 217, 255, .16), transparent 24%),
    linear-gradient(160deg, #111827 0%, #070b13 52%, #141217 100%);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 42px;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.brand,
.pill,
.delay,
#restart,
.toast {
  border: 1px solid rgba(255, 255, 255, .14);
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .22);
  backdrop-filter: blur(14px);
}

.brand {
  min-width: 0;
  /* 左上のポータルバー（戻る + Xで共有）と重ならないよう内側を空ける */
  padding: 10px 12px 10px 130px;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meters {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pill {
  height: 42px;
  min-width: 66px;
  padding: 6px 9px;
  border-radius: 8px;
  color: var(--ink);
}

.pill span,
.delay span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.pill b {
  display: block;
  margin-top: 5px;
  font-size: 17px;
  line-height: 1;
}

.delay {
  position: relative;
  width: 80px;
  height: 42px;
  padding: 7px 8px;
  border-radius: 8px;
  overflow: hidden;
}

.delay i {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--shadow), var(--line));
  transform-origin: left center;
  transform: scaleX(.1);
}

#restart {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
  pointer-events: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 6px);
  z-index: 2;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}

.toast.hide {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

/* スマホ（縦持ち・横持ちとも）: 盤面を1pxでも広く取るため、HUDは
   ポータルバーと同じ高さの1行に畳んで右へ寄せる */
@media (max-width: 620px), (max-height: 470px) {
  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px;
  }

  .brand,
  .delay {
    display: none;
  }

  .meters {
    grid-column: 2;
    gap: 6px;
  }

  .pill {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 32px;
    min-width: 0;
    padding: 0 9px;
    border-radius: 999px;
  }

  .pill span {
    display: inline;
    font-size: 9px;
    letter-spacing: .02em;
  }

  .pill b {
    display: inline;
    margin-top: 0;
    font-size: 15px;
  }

  #restart {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    font-size: 17px;
  }

  .toast {
    padding: 8px 12px;
    font-size: 12px;
  }
}
