:root {
  --ink: #0f1d3d;
  --glass: rgba(14, 28, 58, 0.62);
  --glass-strong: rgba(12, 24, 52, 0.9);
  --line: rgba(255, 255, 255, 0.16);
  --accent: #ffd43b;
  --accent-2: #3fb8ff;
  --pink: #ff5c8a;
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #1d3461;
  color: #fff;
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

#c {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none; outline: none;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none; z-index: 5;
}
#hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: 6px; }
.score-box {
  display: flex; align-items: baseline; gap: 4px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 16px 6px 12px;
  font-weight: 900; font-size: 26px; line-height: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.score-icon { width: 20px; height: 20px; color: var(--accent); align-self: center; margin-right: 2px; }
.score-box .slash, .score-box #total { font-size: 17px; opacity: 0.75; }
.score-box.bump { animation: bump 0.45s ease; }
@keyframes bump { 30% { transform: scale(1.18); } 100% { transform: scale(1); } }
.timer-box {
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px; padding: 5px 12px;
  font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums;
  display: flex; flex-direction: column; align-self: flex-start;
}
.timer-box .best { font-size: 11px; opacity: 0.7; font-weight: 500; }
.hud-right { display: flex; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  color: #fff; display: grid; place-items: center; padding: 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, background 0.2s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.accent { background: linear-gradient(160deg, #ffe066, #ffb703); color: var(--ink); border-color: rgba(255,255,255,0.5); }
#btn-sound .off { display: none; }
#btn-sound.muted .on { display: none; }
#btn-sound.muted .off { display: block; }

/* 押す場所のヒント */
.press-hint {
  position: fixed; width: 92px; height: 92px; margin: -46px 0 0 -46px;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.9);
  pointer-events: none; z-index: 4;
  animation: pulse 1.3s ease-out infinite;
  display: grid; place-items: center;
}
.press-hint span {
  position: absolute; top: -34px; white-space: nowrap;
  font-weight: 900; font-size: 17px; text-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
@keyframes pulse {
  0% { transform: scale(0.75); opacity: 1; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* トースト */
.toast {
  position: fixed; left: 50%; top: calc(74px + var(--safe-t));
  transform: translate(-50%, -10px); opacity: 0;
  background: var(--glass-strong); border: 1px solid var(--line);
  padding: 8px 18px; border-radius: 999px; font-weight: 800; font-size: 15px;
  pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 8;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* オーバーレイ */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: radial-gradient(ellipse at center, rgba(10, 20, 45, 0.35), rgba(10, 20, 45, 0.7));
}
.card {
  width: min(420px, 100%);
  background: var(--glass-strong); border: 1px solid var(--line);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-radius: 28px; padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: pop 0.45s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.logo { position: relative; display: inline-block; margin: 4px 0 8px; }
.logo h1 {
  margin: 0; font-size: 46px; line-height: 1.05; font-weight: 900; letter-spacing: 0.02em;
  background: linear-gradient(180deg, #fff6a8 0%, #ffd43b 45%, #ff8f3b 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #1b3a8c) drop-shadow(0 6px 14px rgba(0,0,0,0.35));
}
.logo-sub {
  position: absolute; right: -18px; top: -8px;
  background: var(--pink); color: #fff; font-weight: 900; font-size: 14px;
  padding: 3px 9px; border-radius: 999px; transform: rotate(12deg);
}
.lead { font-size: 17px; font-weight: 800; margin: 8px 0 14px; line-height: 1.5; }
.howto {
  text-align: left; margin: 0 0 18px; padding: 12px 14px 12px 30px;
  background: rgba(255, 255, 255, 0.07); border-radius: 16px;
  font-size: 13px; line-height: 1.7; font-weight: 500;
}
kbd {
  display: inline-block; min-width: 20px; padding: 0 5px; margin: 0 1px;
  border-radius: 5px; background: rgba(255,255,255,0.18); border-bottom: 2px solid rgba(0,0,0,0.3);
  font-family: inherit; font-size: 12px; text-align: center; line-height: 18px;
}
@media (pointer: coarse) { .pc-only { display: none; } }
.big-btn {
  border: 0; border-radius: 999px; padding: 14px 34px;
  font-size: 20px; font-weight: 900; color: var(--ink);
  background: linear-gradient(180deg, #ffe680, #ffc21a);
  box-shadow: 0 5px 0 #c98a00, 0 10px 24px rgba(0,0,0,0.3);
  transition: transform 0.1s, box-shadow 0.1s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #c98a00, 0 4px 10px rgba(0,0,0,0.3); }
.big-btn:disabled { opacity: 0.6; }
.big-btn.ghost { background: rgba(255,255,255,0.12); color: #fff; box-shadow: 0 5px 0 rgba(0,0,0,0.25); }
.big-btn.small { font-size: 16px; padding: 12px 20px; }
.load-error { margin-top: 12px; color: #ffb3c1; font-size: 13px; line-height: 1.5; }
.clear-title {
  font-size: 40px; font-weight: 900;
  background: linear-gradient(180deg, #fff6a8, #ffb703);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #1b3a8c);
}
.clear-time { font-size: 30px; font-weight: 900; margin: 10px 0 2px; font-variant-numeric: tabular-nums; }
.clear-best { font-size: 15px; font-weight: 800; color: var(--accent); min-height: 22px; margin-bottom: 16px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* 設定シート */
.sheet {
  position: fixed; inset: 0; z-index: 12;
  display: flex; justify-content: flex-end;
  background: rgba(6, 12, 28, 0.35);
}
.sheet-inner {
  width: min(420px, 100%); height: 100%;
  background: var(--glass-strong); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  animation: slideIn 0.3s cubic-bezier(.2,.9,.3,1);
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
}
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 600px) {
  .sheet { align-items: flex-end; }
  .sheet-inner {
    width: 100%; height: auto; max-height: 86%;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 24px 24px 0 0;
    animation: slideUp 0.3s cubic-bezier(.2,.9,.3,1);
  }
  @keyframes slideUp { from { transform: translateY(60px); opacity: 0; } to { transform: none; opacity: 1; } }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px 20px; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 900; }
.sheet-body { overflow-y: auto; padding: 4px 16px 12px; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 16px 16px; border-top: 1px solid var(--line); }
.sheet-foot .big-btn { flex: 1; }
.sec { margin: 10px 0 16px; }
.sec-title { font-size: 13px; font-weight: 800; opacity: 0.75; margin: 0 4px 8px; display: flex; justify-content: space-between; }
.items-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.item-card {
  display: grid; grid-template-columns: 28px 1fr; grid-template-rows: auto auto;
  align-items: center; column-gap: 6px; row-gap: 6px;
  background: rgba(255,255,255,0.07); border: 1px solid var(--line);
  border-radius: 14px; padding: 9px 10px;
}
.item-card .ico { font-size: 22px; width: 28px; text-align: center; line-height: 1; }
.item-card .nm { font-size: 14px; font-weight: 800; white-space: nowrap; }
.item-card .stepper { grid-column: 1 / -1; justify-content: space-between; background: rgba(0,0,0,0.18); border-radius: 999px; padding: 3px; }
.item-card .nm small { display: block; font-size: 10px; opacity: 0.6; font-weight: 500; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 30px; height: 30px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,0.16); color: #fff; font-size: 18px; font-weight: 900; line-height: 1;
}
.stepper button:active { background: rgba(255,255,255,0.3); }
.stepper .val { min-width: 18px; text-align: center; font-weight: 900; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: rgba(255,255,255,0.07); color: #fff;
  padding: 8px 12px; border-radius: 999px; font-size: 13px; font-weight: 800;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: #fff; color: var(--ink); border-color: #fff; }
.chip .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.2); display: inline-block; }
.chip .pal { display: inline-flex; }
.chip .pal i { width: 9px; height: 14px; display: inline-block; }
.chip .pal i:first-child { border-radius: 7px 0 0 7px; }
.chip .pal i:last-child { border-radius: 0 7px 7px 0; }
.note { font-size: 11px; opacity: 0.6; margin: 6px 4px 0; line-height: 1.5; }
