:root {
  --teal: #3fe0e6;
  --teal-2: #1aa6b8;
  --gold: #f0c869;
  --gold-2: #a57b2e;
  --ink: #e9f6ff;
  --ink-dim: #9fb6c8;
  --glass: rgba(8, 22, 36, 0.62);
  --glass-strong: rgba(6, 16, 28, 0.88);
  --line: rgba(120, 230, 255, 0.22);
  --danger: #ff6b5e;
  --radius: 18px;
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic UI", system-ui, sans-serif;
  --digit: "Orbitron", "M PLUS Rounded 1c", monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #02070d; color: var(--ink); font-family: var(--font); }
body { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
button { font-family: inherit; color: inherit; cursor: pointer; }
img { -webkit-user-drag: none; }
.hidden, [hidden] { display: none !important; }

/* ---- 背景 ---- */
#bg {
  position: fixed; inset: 0; z-index: 0;
  background: url(../assets/img/bg_landscape.webp) center / cover no-repeat;
  filter: saturate(1.05);
}
#bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse 70% 65% at 50% 52%, rgba(2, 8, 16, 0.55), rgba(2, 8, 16, 0.15) 70%, rgba(2, 8, 16, 0.5));
}
@media (max-aspect-ratio: 1/1) { #bg { background-image: url(../assets/img/bg_portrait.webp); } }
#motes { position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.mote {
  position: absolute; bottom: -10px; width: 6px; height: 6px; border-radius: 50%;
  background: radial-gradient(circle, rgba(170, 255, 255, 0.95), rgba(80, 220, 255, 0) 70%);
  animation: rise linear infinite;
}
@keyframes rise {
  0% { transform: translate(0, 0) scale(0.6); opacity: 0; }
  10% { opacity: 0.9; }
  100% { transform: translate(var(--dx, 30px), -105vh) scale(1.2); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .mote { display: none; } }

/* ---- レイアウト ---- */
#app {
  position: fixed; inset: 0; z-index: 2;
  display: grid; grid-template-rows: auto auto 1fr auto;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  gap: 6px;
}
.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
}

/* ---- HUD ---- */
#hud {
  justify-self: center; width: min(720px, 100%);
  display: grid; grid-template-columns: 48px 1fr 84px 1fr 48px; align-items: center; gap: 8px;
  height: 64px; padding: 0 10px; border-radius: 22px;
  position: relative;
}
#hud::before { /* 真鍮のフチ */
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1.5px; pointer-events: none;
  background: linear-gradient(120deg, rgba(240, 200, 105, 0.9), rgba(120, 90, 40, 0.3) 40%, rgba(240, 200, 105, 0.8));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
}
.iconbtn {
  width: 46px; height: 46px; border-radius: 14px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(40, 90, 110, 0.55), rgba(10, 30, 45, 0.7));
  display: grid; place-items: center; position: relative; padding: 0;
  transition: transform 0.12s, box-shadow 0.2s;
}
.iconbtn img { width: 34px; height: 34px; }
.iconbtn:hover { box-shadow: 0 0 16px rgba(80, 230, 255, 0.45); }
.iconbtn:active { transform: scale(0.92); }
.iconbtn:disabled { opacity: 0.4; }
.badge {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--gold); color: #3a2500; font: 800 11px/18px var(--font);
}
.counter {
  justify-self: center; display: flex; align-items: center; gap: 6px;
  padding: 4px 12px 4px 6px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(10, 25, 35, 0.6));
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(90, 220, 255, 0.18);
}
.counter img { width: 34px; height: 34px; }
.counter span {
  font: 800 24px/1 var(--digit); letter-spacing: 1px; color: #8ff3ff;
  text-shadow: 0 0 10px rgba(80, 230, 255, 0.8); min-width: 3.2ch; text-align: right;
  font-variant-numeric: tabular-nums;
}
.counter.neg span { color: #ff8b7e; text-shadow: 0 0 10px rgba(255, 90, 70, 0.8); }
#drone {
  width: 84px; height: 84px; margin-top: 6px; border: none; padding: 0; background: none;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6)) drop-shadow(0 0 12px rgba(80, 230, 255, 0.35));
  transition: transform 0.15s;
  animation: hover 3.2s ease-in-out infinite;
  z-index: 3;
}
#drone img { width: 100%; height: 100%; }
#drone:active { transform: scale(0.9); }
@keyframes hover { 50% { translate: 0 -4px; } }
#subinfo { justify-self: center; font-size: 12.5px; color: var(--ink-dim); letter-spacing: 0.04em; min-height: 18px; text-align: center; margin-top: 22px; }
#subinfo b { color: var(--gold); font-weight: 700; }
#subinfo .daily { color: #8ff3ff; }

/* ドローンのふきだし */
.bubble {
  position: fixed; left: 50%; top: calc(max(8px, env(safe-area-inset-top)) + 112px); z-index: 30;
  transform: translate(-50%, -6px) scale(0.92); opacity: 0; pointer-events: none;
  background: rgba(240, 252, 255, 0.95); color: #0b2733; font-weight: 700; font-size: 14px;
  padding: 8px 14px; border-radius: 14px; width: max-content; max-width: min(92vw, 560px); text-align: center; line-height: 1.45;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4), 0 0 18px rgba(120, 240, 255, 0.4);
  transition: opacity 0.25s, transform 0.25s;
}
.bubble::before {
  content: ""; position: absolute; left: 50%; top: -7px; margin-left: -7px;
  border: 7px solid transparent; border-top: 0; border-bottom-color: rgba(240, 252, 255, 0.95);
}
.bubble.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---- 盤面 ---- */
#boardArea { position: relative; min-height: 0; overflow: hidden; border-radius: 16px; }
#board { position: absolute; inset: 0; display: block; touch-action: none; cursor: pointer; }
.notice {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-radius: 14px;
  background: var(--glass-strong); border: 1px solid var(--line); font-size: 14px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); pointer-events: none; white-space: nowrap;
}
#toast { animation: toast 2.4s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 8px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid rgba(140, 240, 255, 0.25); border-top-color: var(--teal); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#pauseCover {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px;
  background: rgba(3, 10, 18, 0.72); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-radius: 16px;
}
#pauseCover img { width: 120px; height: 120px; animation: hover 3s ease-in-out infinite; }
#pauseCover p { margin: 0 0 8px; font-size: 20px; font-weight: 800; letter-spacing: 0.1em; }

/* ---- ツールバー ---- */
#toolbar {
  justify-self: center; width: min(720px, 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 8px; border-radius: 20px;
}
.tool, .seg button {
  height: 48px; min-width: 48px; padding: 0 10px; border-radius: 14px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(40, 90, 110, 0.5), rgba(10, 30, 45, 0.7));
  display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 13px; font-weight: 700;
  transition: transform 0.12s, background 0.2s, box-shadow 0.2s;
}
.tool img, .seg img { width: 30px; height: 30px; }
.tool.sm { min-width: 42px; padding: 0 4px; }
.tool.sm img { width: 26px; height: 26px; }
.tool:active, .seg button:active { transform: scale(0.94); }
.tool:disabled { opacity: 0.38; }
.seg { display: flex; gap: 0; border-radius: 15px; padding: 2px; background: rgba(0, 0, 0, 0.35); box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.6); }
.seg button { border: none; background: none; border-radius: 12px; height: 44px; color: var(--ink-dim); }
.seg button.on {
  color: #062028; background: linear-gradient(180deg, #a6fbff, #36c7d6);
  box-shadow: 0 0 14px rgba(80, 230, 255, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.seg button[data-mode="flag"].on { background: linear-gradient(180deg, #ffd0b8, #ff7a5c); box-shadow: 0 0 14px rgba(255, 120, 90, 0.6); }
.zoom { display: flex; gap: 4px; }

/* ---- モーダル ---- */
#modalRoot { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 12px; }
.scrim { position: absolute; inset: 0; background: rgba(1, 6, 12, 0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal {
  position: relative; display: none; width: min(560px, 100%); max-height: calc(100dvh - 24px); overflow: auto;
  border-radius: 24px; padding: 20px 20px 16px; background: var(--glass-strong);
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
  scrollbar-width: thin;
}
.modal.show { display: block; }
.modal::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1.5px; pointer-events: none;
  background: linear-gradient(140deg, rgba(240, 200, 105, 0.95), rgba(60, 220, 240, 0.35) 45%, rgba(240, 200, 105, 0.8));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
}
@keyframes pop { from { transform: scale(0.9) translateY(10px); opacity: 0; } }
.modal h2 { margin: 2px 0 12px; font-size: 22px; display: flex; align-items: center; gap: 8px; }
.modal h2 img { width: 36px; height: 36px; }
.modal h3 { margin: 14px 0 8px; font-size: 14px; color: var(--gold); letter-spacing: 0.06em; }
.logo { display: block; width: min(330px, 78%); margin: -4px auto 0; filter: drop-shadow(0 6px 18px rgba(60, 230, 255, 0.35)); }
.subtitle { text-align: center; margin: 2px 0 2px; font-weight: 800; letter-spacing: 0.3em; color: var(--gold); font-size: 14px; }
.catch { text-align: center; margin: 6px 0 4px; color: var(--ink-dim); font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.card, .tier {
  border-radius: 14px; border: 1px solid var(--line); padding: 10px 6px; text-align: center;
  background: linear-gradient(180deg, rgba(30, 70, 90, 0.5), rgba(8, 22, 34, 0.7));
  transition: transform 0.12s, box-shadow 0.2s, border-color 0.2s;
}
.card b, .tier b { display: block; font-size: 17px; }
.card small, .tier small { display: block; color: var(--ink-dim); font-size: 11.5px; margin-top: 2px; line-height: 1.35; }
.card.on, .tier.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(240, 200, 105, 0.35); background: linear-gradient(180deg, rgba(90, 80, 40, 0.5), rgba(20, 24, 20, 0.7)); }
.card:active, .tier:active { transform: scale(0.96); }
.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tier .gems { color: #7ff3ff; letter-spacing: 2px; font-size: 12px; }
.custom { margin-top: 10px; display: grid; gap: 6px; padding: 10px 12px; border-radius: 14px; background: rgba(0, 0, 0, 0.3); }
.custom label { display: grid; grid-template-columns: 3.5em 1fr 3em; align-items: center; gap: 8px; font-size: 13px; }
.custom output { text-align: right; font-family: var(--digit); font-size: 13px; color: #8ff3ff; }
.note { margin: 0; font-size: 11.5px; color: var(--ink-dim); }
.btn {
  height: 46px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(40, 90, 110, 0.55), rgba(10, 30, 45, 0.75));
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; font-weight: 700;
  transition: transform 0.12s, box-shadow 0.2s;
}
.btn img { width: 28px; height: 28px; }
.btn:hover { box-shadow: 0 0 16px rgba(80, 230, 255, 0.35); }
.btn:active { transform: scale(0.95); }
.btn.primary { color: #08222a; border-color: rgba(255, 255, 255, 0.4); background: linear-gradient(180deg, #b6fdff, #2fc0d2); box-shadow: 0 0 20px rgba(80, 230, 255, 0.45); }
.btn.big { width: 100%; height: 56px; font-size: 18px; margin-top: 16px; }
.btn.daily { width: 100%; margin-top: 8px; background: linear-gradient(180deg, rgba(110, 90, 40, 0.6), rgba(40, 30, 12, 0.75)); border-color: rgba(240, 200, 105, 0.5); }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-dim); height: 38px; }
.btn.danger { color: #ffb4ab; border-color: rgba(255, 107, 94, 0.5); }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
.row .btn { flex: 1 1 auto; }

/* 結果 */
#m-result { text-align: center; }
.resultDrone { width: 120px; height: 120px; margin: -6px auto 0; display: block; animation: hover 2.6s ease-in-out infinite; }
#m-result h2 { justify-content: center; font-size: 26px; margin: 0; letter-spacing: 0.08em; }
.resultLine { margin: 4px 0 6px; color: var(--ink-dim); font-size: 14px; }
.bigtime { font: 800 44px/1.1 var(--digit); color: #a6f8ff; text-shadow: 0 0 18px rgba(80, 230, 255, 0.7); }
.bigtime small { font-size: 20px; }
.badge-new { display: inline-block; margin: 6px 0 0; padding: 3px 12px; border-radius: 99px; font: 800 13px var(--digit); letter-spacing: 0.15em; color: #3a2500; background: linear-gradient(90deg, #ffe39a, #f0b84a); box-shadow: 0 0 18px rgba(255, 210, 110, 0.7); animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { to { box-shadow: 0 0 30px rgba(255, 220, 120, 1); } }
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0 4px; }
.statgrid div { background: rgba(0, 0, 0, 0.3); border-radius: 12px; padding: 7px 4px; }
.statgrid b { display: block; font: 800 17px var(--digit); color: var(--ink); }
.statgrid span { font-size: 11px; color: var(--ink-dim); }
.best { margin-top: 8px; font-size: 13px; }
.best ol { margin: 4px auto 0; padding: 0; list-style: none; max-width: 320px; }
.best li { display: flex; justify-content: space-between; padding: 3px 10px; border-radius: 8px; color: var(--ink-dim); font-family: var(--digit); font-size: 12.5px; }
.best li.me { background: rgba(240, 200, 105, 0.18); color: var(--gold); }

/* 記録 */
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { flex: 1; height: 36px; white-space: nowrap; padding: 0 4px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); font-weight: 700; font-size: 13px; }
.tabs button.on { background: linear-gradient(180deg, #a6fbff, #36c7d6); color: #062028; }
.stattable { width: 100%; border-collapse: collapse; font-size: 13px; }
.stattable th, .stattable td { padding: 6px 4px; text-align: center; border-bottom: 1px solid rgba(120, 230, 255, 0.12); }
.stattable th { color: var(--gold); font-weight: 700; font-size: 12px; }
.stattable td { font-family: var(--digit); font-size: 12.5px; }
.stattable td:first-child { font-family: var(--font); font-weight: 700; }
.besttimes { margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: 12px; }
.besttimes h4 { margin: 0 0 4px; font-size: 12px; color: var(--gold); }
.besttimes ol { margin: 0; padding-left: 18px; font-family: var(--digit); color: var(--ink-dim); }
.dailylog { margin-top: 12px; font-size: 12.5px; color: var(--ink-dim); }

/* 設定 */
.settings { display: grid; gap: 10px; }
.slider { display: grid; gap: 4px; font-size: 14px; font-weight: 700; }
.slider output { color: #8ff3ff; font-family: var(--digit); font-size: 12px; margin-left: 6px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.toggle input { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: rgba(255, 255, 255, 0.15); position: relative; flex: none; transition: background 0.2s; cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #dfefff; transition: transform 0.2s; }
.toggle input:checked { background: var(--teal-2); box-shadow: 0 0 10px rgba(80, 230, 255, 0.5); }
.toggle input:checked::after { transform: translateX(18px); }
input[type=range] { width: 100%; accent-color: var(--teal); }

/* 遊び方 */
.help { font-size: 14px; line-height: 1.65; }
.help p { margin: 0 0 10px; }
.help .promise { padding: 10px 12px; border-radius: 12px; background: rgba(60, 220, 240, 0.1); border: 1px solid var(--line); }
.help table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-bottom: 10px; }
.help th, .help td { border-bottom: 1px solid rgba(120, 230, 255, 0.12); padding: 5px 4px; text-align: left; vertical-align: top; }
.help th { color: var(--gold); }
.help td:first-child { white-space: nowrap; }
.help h4 { margin: 8px 0 4px; color: var(--gold); }
.help ul { margin: 0 0 10px; padding-left: 20px; }

/* ---- スマホ ---- */
@media (max-width: 560px) {
  #hud { grid-template-columns: 42px 1fr 70px 1fr 42px; height: 56px; gap: 4px; padding: 0 6px; }
  .iconbtn { width: 40px; height: 40px; }
  .iconbtn img { width: 30px; height: 30px; }
  .counter { padding: 3px 8px 3px 4px; gap: 3px; }
  .counter img { width: 26px; height: 26px; }
  .counter span { font-size: 19px; }
  #drone { width: 72px; height: 72px; }
  .bubble { top: calc(max(8px, env(safe-area-inset-top)) + 96px); font-size: 13px; }
  #subinfo { margin-top: 18px; font-size: 11.5px; }
  .tool, .seg button { height: 44px; min-width: 42px; padding: 0 6px; font-size: 12px; }
  .seg button { height: 40px; white-space: nowrap; padding: 0 8px 0 4px; }
  .seg img { width: 26px; height: 26px; }
  .btn.daily { font-size: 12.5px; padding: 0 8px; white-space: nowrap; }
  .tool span { display: none; }
  .tool.sm { min-width: 38px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .tier small { font-size: 10.5px; }
  .modal { padding: 16px 14px 12px; }
  .besttimes { grid-template-columns: 1fr; }
  .tabs button { font-size: 11.5px; }
  .help table { font-size: 11.5px; }
}
@media (max-height: 520px) and (min-width: 561px) {
  #hud { height: 52px; }
  #drone { width: 64px; height: 64px; margin-top: 0; }
}
