:root {
  --ink: #f4efe6;
  --ink-soft: #b9b3cf;
  --night: #0b1030;
  --panel: rgba(18, 20, 52, 0.9);
  --line: rgba(255, 255, 255, 0.14);
  --primary: #ff6b6b;
  --primary-dark: #c9424e;
  --gold: #ffd166;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: "Zen Maru Gothic", system-ui, sans-serif;
  font-weight: 500;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
}

#game { display: block; width: 100%; height: 100%; touch-action: none; }

.hidden { display: none !important; }

/* HUD */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  pointer-events: none;
}
.hud-left { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.hud-center { text-align: center; }
.hud-right { justify-self: end; text-align: right; }
.count {
  font-family: "Kaisei Decol", serif;
  font-size: 48px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 18px rgba(255, 209, 102, 0.55);
  transition: transform 0.1s;
}
.count.pop { transform: scale(1.15); }
.count .of { font-size: 20px; color: var(--ink-soft); margin-left: 4px; text-shadow: none; }
.hud-sub { font-size: 12px; font-weight: 900; color: var(--ink-soft); }
.hud-best { font-family: "Kaisei Decol", serif; font-size: 20px; color: var(--gold); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}
.badge.practice { background: #6c7cff; }
.badge.big { font-size: 14px; padding: 4px 14px; }

.hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  text-align: center;
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  opacity: 0.85;
  pointer-events: none;
  animation: breathe 1.8s ease-in-out infinite alternate;
}
@keyframes breathe { from { opacity: 0.45; } to { opacity: 0.95; } }

.icon-btn {
  position: absolute;
  left: 14px;
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  display: grid; place-items: center;
  cursor: pointer;
  z-index: 5;
}

.toast {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Kaisei Decol", serif;
  font-size: 36px;
  color: #fff;
  text-shadow: 0 0 16px rgba(255, 209, 102, 0.9), 0 0 4px rgba(255, 107, 107, 0.9);
  pointer-events: none;
  white-space: nowrap;
  animation: toast 1.1s ease-out forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

/* 画面 */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 6, 20, 0.35);
  overflow-y: auto;
  z-index: 10;
}
.panel {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 26px 20px 20px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  margin: auto;
}
.logo {
  font-family: "Kaisei Decol", serif;
  font-size: 54px;
  line-height: 1.1;
  color: #fff;
  letter-spacing: 0.08em;
  text-shadow: 0 0 22px rgba(255, 107, 107, 0.75), 0 0 6px rgba(255, 209, 102, 0.9);
}
.catch { font-size: 14px; font-weight: 900; color: var(--gold); margin-top: 6px; }
.day { font-size: 13px; font-weight: 900; color: var(--ink-soft); margin: 8px 0 14px; }
.howto {
  list-style: none;
  padding: 12px 14px;
  margin: 0 0 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  text-align: left;
  font-size: 14px;
}
.howto li { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; }
.howto .num { flex: none; font-family: "Kaisei Decol", serif; color: var(--primary); }
.note { font-size: 12px; color: var(--ink-soft); margin: 0 0 16px; line-height: 1.7; }

.btn {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 14px 12px;
  border: none;
  border-radius: 16px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}
.btn small { display: block; font-size: 11px; font-weight: 500; opacity: 0.85; margin-top: 2px; }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-dark); }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn.ghost { background: transparent; border: 2px solid var(--line); color: var(--ink-soft); font-size: 15px; }
.btn.x { background: #000; color: #fff; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); }
.btn.sub { font-size: 14px; padding: 11px; }
.share-row { margin: 14px 0 6px; }
.share-row .btn { margin: 6px 0; }

.done-box { background: rgba(255, 209, 102, 0.08); border: 1px solid rgba(255, 209, 102, 0.25); border-radius: 16px; padding: 12px; margin-bottom: 6px; }
.done-label { font-size: 12px; color: var(--ink-soft); font-weight: 900; }
.done-score { font-family: "Kaisei Decol", serif; font-size: 34px; color: var(--gold); }
.done-of { font-size: 18px; color: var(--ink-soft); }
.done-rank { font-size: 14px; font-weight: 900; }
.countdown { font-size: 13px; color: var(--ink-soft); font-weight: 900; margin: 6px 0 4px; }
.countdown .cd { font-family: "Kaisei Decol", serif; color: var(--ink); letter-spacing: 0.05em; }
.stats-line { font-size: 13px; color: var(--ink-soft); margin-top: 10px; font-weight: 900; }

.res-score { font-family: "Kaisei Decol", serif; color: #fff; line-height: 1; margin-top: 6px; text-shadow: 0 0 22px rgba(255, 209, 102, 0.6); }
.res-score #res-count { font-size: 80px; }
.res-score .unit { font-size: 26px; color: var(--ink-soft); text-shadow: none; }
.res-sub { font-size: 15px; font-weight: 900; color: var(--gold); margin-top: 6px; }
.res-best {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--gold);
  color: #2b2140;
  font-weight: 900;
  font-size: 13px;
  animation: pulse 0.9s ease-in-out infinite alternate;
}
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
.rank-box { margin-top: 14px; background: rgba(255, 255, 255, 0.06); border-radius: 16px; padding: 12px; }
.rank-label { font-size: 12px; color: var(--ink-soft); font-weight: 900; }
.rank-name { font-family: "Kaisei Decol", serif; font-size: 28px; margin: 2px 0 4px; color: #fff; }
.rank-desc { font-size: 13px; line-height: 1.6; color: var(--ink-soft); }

.portal-link { display: inline-block; margin-top: 12px; font-size: 12px; font-weight: 900; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; }

/* 保存・コピーできない環境向けの案内 */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.overlay-box { width: 100%; max-width: 380px; max-height: 92vh; overflow-y: auto; background: #fff; color: #2b2140; border-radius: 20px; padding: 18px 16px 10px; text-align: center; }
.ov-msg { margin: 0 0 12px; font-weight: 800; font-size: 14px; line-height: 1.6; }
.ov-img { width: 100%; border-radius: 12px; margin-bottom: 10px; -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto; }
.ov-text { width: 100%; height: 150px; font: inherit; font-size: 13px; border: 1px solid #ddd; border-radius: 10px; padding: 8px; margin-bottom: 6px; user-select: text; -webkit-user-select: text; }
.overlay-box .btn.ghost { color: #6b6283; border-color: #e7e1f0; }
