:root {
  --ink: #4a3b33;
  --ink-soft: #8a7868;
  --surface: #fffdf9;
  --primary: #ff7a59;
  --primary-2: #ff6f91;
  --secondary: #4cc4c9;
  --shadow-soft: 0 10px 30px rgba(70, 45, 30, .16);
  --shadow-card: 0 18px 50px rgba(40, 30, 25, .28);
  --glass: rgba(255, 255, 255, .18);
  --glass-bd: rgba(255, 255, 255, .45);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* 画面の外側（PCのガター）。落ち着いた色で本体を引き立てる */
#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(110% 80% at 50% -10%, #2b4a63 0%, #1c2e3e 55%, #16222e 100%);
}

#app {
  position: relative;
  width: 100%; height: 100%;
  overflow: hidden;
  background: #cfeaff;
}

/* 広い画面ではスマホ風フレームに */
@media (min-width: 600px), (min-aspect-ratio: 13/10) {
  #app {
    width: min(440px, 96vw);
    height: min(94vh, 920px);
    border-radius: 34px;
    box-shadow: var(--shadow-card), 0 0 0 7px #11202c, 0 0 0 9px rgba(255,255,255,.06);
  }
}

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

/* ===== 画面共通 ===== */
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 18px) 22px calc(env(safe-area-inset-bottom) + 18px);
  text-align: center;
}
.screen.active { display: flex; animation: fade-up .4s cubic-bezier(.2,.8,.25,1); }
@keyframes fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

.screen-h { font-weight: 900; font-size: clamp(20px, 6vw, 27px); color: #fff; letter-spacing: .02em; text-shadow: 0 2px 12px rgba(20,40,60,.35); margin-bottom: 4px; }
.screen-sub { color: rgba(255,255,255,.92); font-size: 13px; margin-bottom: 16px; text-shadow: 0 1px 6px rgba(0,0,0,.25); }

/* ===== ボタン ===== */
.btn {
  position: relative; border: none; cursor: pointer;
  border-radius: 18px; padding: 15px 26px;
  font-family: inherit; font-weight: 800; font-size: clamp(15px, 4.4vw, 18px);
  color: #fff; margin: 6px;
  min-width: min(250px, 80vw);
  background: linear-gradient(180deg, #ff9476, var(--primary));
  box-shadow: 0 8px 20px rgba(255,108,80,.38), inset 0 1px 0 rgba(255,255,255,.5);
  transition: transform .12s cubic-bezier(.2,.8,.3,1.4), box-shadow .12s ease, filter .12s ease;
}
.btn .btn-ico { margin-right: 8px; }
.btn.secondary { background: linear-gradient(180deg, #62d4d8, var(--secondary)); box-shadow: 0 8px 20px rgba(60,190,195,.38), inset 0 1px 0 rgba(255,255,255,.5); }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255,255,255,.7); }
.btn.wide { min-width: min(420px, 100%); width: 100%; max-width: 420px; }
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px) scale(.99); box-shadow: 0 3px 10px rgba(255,108,80,.34); }
.btn:disabled { filter: grayscale(.55) opacity(.55); box-shadow: var(--shadow-soft); transform: none; }

.icon-btn {
  position: absolute; top: calc(env(safe-area-inset-top) + 16px); left: 18px; z-index: 6;
  width: 46px; height: 46px; border-radius: 16px; border: none; cursor: pointer;
  background: var(--glass); border: 1px solid var(--glass-bd); backdrop-filter: blur(12px);
  color: #fff; font-size: 30px; line-height: 42px;
  box-shadow: var(--shadow-soft);
}
.icon-btn:active { transform: scale(.92); }

/* ===== タイトル ===== */
#screen-title { background: linear-gradient(180deg, #8ec8ff 0%, #bfe6ff 50%, #ffe7c4 78%, #ffd79c 100%); overflow: hidden; }
.title-inner { display: flex; flex-direction: column; align-items: center; z-index: 2; }
.title-dog { width: clamp(132px, 36vw, 188px); height: auto; animation: run-bob 1.1s ease-in-out infinite; filter: drop-shadow(0 12px 10px rgba(50,40,30,.22)); }
@keyframes run-bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-10px) rotate(2deg); } }
.logo { line-height: .9; margin: 6px 0 8px; color: #fff; }
.logo-l1 { display: block; font-weight: 800; font-size: clamp(26px, 8.4vw, 38px); color: #ff8a5c; text-shadow: 0 2px 0 #fff; }
.logo-l2 { display: block; font-weight: 900; font-size: clamp(58px, 19vw, 86px); color: #fff; -webkit-text-stroke: 3px #ff7a59; text-shadow: 0 8px 18px rgba(255,120,80,.45); }
.lead { font-weight: 700; color: #3c6b8a; font-size: clamp(13px, 4vw, 16px); margin-bottom: 22px; }
.title-btns { display: flex; flex-direction: column; }
.best-chip { margin-top: 20px; background: var(--glass); border: 1px solid var(--glass-bd); backdrop-filter: blur(10px); color: #345; padding: 8px 22px; border-radius: 999px; font-weight: 700; font-size: 14px; box-shadow: var(--shadow-soft); }
.best-chip b { font-size: 18px; color: var(--primary); margin: 0 2px; }
.icon-btn.mute { left: auto; right: 18px; font-size: 24px; line-height: 46px; }
.name-input {
  margin: 0 0 16px; width: min(280px, 80vw);
  padding: 12px 18px; border-radius: 14px; border: 1px solid var(--glass-bd);
  background: rgba(255,255,255,.88); color: var(--ink);
  font-family: inherit; font-weight: 700; font-size: 15px; text-align: center;
  box-shadow: var(--shadow-soft); outline: none;
}
.name-input::placeholder { color: #b3a595; font-weight: 600; }
.share-row { display: flex; gap: 10px; width: 100%; max-width: 460px; margin: 2px auto 10px; }
.share-row .btn { flex: 1 1 0; min-width: 0; margin: 0; }

/* やわらかい光の玉（ボケ） */
.bokeh { position: absolute; inset: 0; overflow: hidden; z-index: 1; pointer-events: none; }
.bokeh i { position: absolute; border-radius: 50%; background: radial-gradient(circle at 35% 35%, rgba(255,255,255,.9), rgba(255,255,255,0) 70%); filter: blur(2px); animation: rise 9s ease-in-out infinite; }
.bokeh i:nth-child(1){ width: 90px; height: 90px; left: 8%; top: 20%; animation-delay: 0s; }
.bokeh i:nth-child(2){ width: 54px; height: 54px; right: 12%; top: 14%; animation-delay: 1.4s; opacity: .8; }
.bokeh i:nth-child(3){ width: 130px; height: 130px; left: 18%; bottom: 18%; animation-delay: 2.6s; opacity: .5; }
.bokeh i:nth-child(4){ width: 70px; height: 70px; right: 20%; bottom: 26%; animation-delay: 3.6s; opacity: .7; }
.bokeh i:nth-child(5){ width: 40px; height: 40px; right: 34%; top: 42%; animation-delay: 1s; opacity: .9; }
@keyframes rise { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-26px) scale(1.08); } }

/* ===== キャラ選択 ===== */
#screen-select { background: linear-gradient(180deg, #6fb6f0, #a9d8ff); justify-content: flex-start; padding-top: calc(env(safe-area-inset-top) + 74px); }
.char-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; width: min(460px, 94%); overflow-y: auto; padding: 6px 4px 14px; flex: 1; -webkit-overflow-scrolling: touch; }
@media (min-width: 540px) { .char-grid { grid-template-columns: repeat(3, 1fr); } }
.char-card {
  position: relative; background: var(--surface); border-radius: 22px; padding: 12px 6px 14px;
  display: flex; flex-direction: column; align-items: center; cursor: pointer;
  border: 2.5px solid transparent; box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255,255,255,.7);
  transition: transform .16s cubic-bezier(.2,.8,.3,1.3), border-color .16s ease, box-shadow .16s ease;
  animation: card-pop .45s backwards;
}
@keyframes card-pop { from { opacity: 0; transform: scale(.82) translateY(10px); } to { opacity: 1; transform: none; } }
.char-card:active { transform: scale(.96); }
.char-card.selected { border-color: var(--primary); transform: translateY(-4px) scale(1.03); box-shadow: 0 16px 34px rgba(255,110,80,.34); }
.char-card canvas { width: 92px; height: 92px; }
.char-card .cname { font-weight: 800; font-size: 15px; margin-top: 4px; color: var(--ink); }
.char-card.selected::after { content: "✓"; position: absolute; top: 8px; right: 10px; width: 24px; height: 24px; line-height: 24px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 15px; font-weight: 900; }
.select-bar { width: 100%; max-width: 460px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding-top: 6px; }
.select-bar .btn { margin: 0; }
.select-bar .btn.ghost { min-width: 0; flex: 0 1 auto; }
.select-bar .btn.wide { flex: 1 1 220px; width: auto; min-width: 0; max-width: none; }

/* ===== トリミング ===== */
#screen-crop { background: #1d2530; color: #fff; justify-content: flex-start; padding-top: calc(env(safe-area-inset-top) + 74px); }
#crop-stage { position: relative; max-width: 100%; max-height: 70vh; touch-action: none; margin: 8px 0 auto; }
#crop-canvas { max-width: 100%; max-height: 70vh; display: block; border-radius: 16px; box-shadow: var(--shadow-card); }
#crop-overlay { position: absolute; left: 0; top: 0; max-width: 100%; max-height: 70vh; border-radius: 16px; touch-action: none; cursor: crosshair; }

/* ===== プレイ中 ===== */
#screen-play { justify-content: flex-start; background: transparent; pointer-events: none; }
#screen-play.active { pointer-events: auto; }
.hud { position: absolute; top: calc(env(safe-area-inset-top) + 14px); left: 0; right: 0; display: flex; justify-content: space-between; padding: 0 16px; }
.hud-pill {
  display: flex; align-items: baseline; gap: 5px;
  background: var(--glass); border: 1px solid var(--glass-bd); backdrop-filter: blur(12px);
  color: #fff; padding: 9px 18px; border-radius: 18px; font-weight: 900;
  font-size: clamp(20px, 6vw, 26px); box-shadow: var(--shadow-soft);
  text-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.hud-pill .hud-unit { font-size: 13px; font-weight: 700; opacity: .9; }
.hud-pill.coin { font-size: clamp(18px, 5vw, 22px); }
.hud-pill .coin-ico { font-size: 18px; }

.tap-area { position: absolute; inset: 0; background: transparent; border: none; cursor: pointer; display: flex; align-items: flex-end; justify-content: center; padding-bottom: calc(env(safe-area-inset-bottom) + 52px); }
.tap-text {
  font-weight: 800; font-size: clamp(17px, 5vw, 21px); color: #fff;
  background: var(--glass); border: 1px solid var(--glass-bd); backdrop-filter: blur(10px);
  padding: 12px 28px; border-radius: 999px; box-shadow: var(--shadow-soft);
  text-shadow: 0 1px 4px rgba(0,0,0,.3); animation: tap-pulse 1.1s ease-in-out infinite;
}
.tap-text:empty { display: none; }
@keyframes tap-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

/* ===== リザルト ===== */
#screen-result { background: rgba(15,25,40,.55); backdrop-filter: blur(4px); }
.result-card {
  background: var(--surface); border-radius: 30px; padding: 28px 26px 24px;
  width: min(370px, 90%); display: flex; flex-direction: column; align-items: center;
  box-shadow: var(--shadow-card), inset 0 1px 0 rgba(255,255,255,.8);
  animation: pop .5s cubic-bezier(.2,.9,.3,1.5);
}
@keyframes pop { from { opacity: 0; transform: scale(.72) translateY(20px); } to { opacity: 1; transform: none; } }
.result-cap { font-weight: 700; font-size: 14px; color: var(--ink-soft); letter-spacing: 3px; }
.result-dist { font-weight: 900; font-size: clamp(56px, 19vw, 82px); line-height: 1; color: var(--primary); margin: 4px 0 2px; }
.result-dist small { font-size: .34em; margin-left: 5px; color: var(--ink); }
.result-stats { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink-soft); font-size: 15px; margin: 6px 0 18px; }
.result-stats .dot { opacity: .5; }

@media (max-height: 540px) {
  .title-dog { width: clamp(96px, 22vh, 130px); }
  .logo { margin: 2px 0 4px; }
  .lead { margin-bottom: 12px; }
  .title-btns { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .best-chip { margin-top: 10px; }
  .title-inner { transform: scale(.94); }
}
