
  :root {
    --bg1: #ffe7c2;
    --bg2: #ffc6d9;
    --ink: #3b2a4a;
    --accent: #ff5e8a;
    --accent2: #ffb347;
    --card: rgba(255, 255, 255, 0.82);
    --shadow: 0 8px 24px rgba(120, 60, 90, 0.18);
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body {
    margin: 0; height: 100%;
    font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
    color: var(--ink);
    background:
      radial-gradient(circle at 15% 20%, rgba(255,255,255,.55) 0 60px, transparent 61px),
      radial-gradient(circle at 85% 75%, rgba(255,255,255,.4) 0 90px, transparent 91px),
      linear-gradient(160deg, var(--bg1), var(--bg2));
    overflow: hidden;
    user-select: none; -webkit-user-select: none;
  }
  .app {
    height: 100dvh;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 8px; padding: 8px 12px;
  }
  .hud {
    width: var(--stage-w);
    display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: stretch;
  }
  .title {
    grid-column: 1 / -1;
    text-align: center; font-weight: 800; font-size: clamp(18px, 4.6vw, 24px);
    letter-spacing: .06em; margin: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }
  .card {
    background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
    padding: 6px 12px; display: flex; flex-direction: column; justify-content: center;
    border: 2px solid rgba(255,255,255,.9);
  }
  .card .label { font-size: 11px; font-weight: 800; letter-spacing: .12em; opacity: .6; }
  .card .value { font-size: clamp(20px, 5.4vw, 26px); font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
  .card.next { align-items: center; padding: 4px 10px; }
  #nextCanvas { width: 52px; height: 52px; display: block; }

  .stage {
    --stage-w: min(420px, calc((100vw - 24px) * var(--stage-width-ratio, 0.7)), calc((100dvh - 210px) * 0.735294));
    position: relative;
    width: var(--stage-w);
    aspect-ratio: 400 / 544;
    flex-shrink: 0;
    border-radius: 22px;
    box-shadow: var(--shadow), inset 0 0 0 4px rgba(255,255,255,.9);
    overflow: visible;
    touch-action: none;
    cursor: pointer;
    background: #fff8ee;
  }
  .app { --stage-w: min(420px, calc((100vw - 24px) * var(--stage-width-ratio, 0.7)), calc((100dvh - 210px) * 0.735294)); }
  #game { position: absolute; top: 0; width: 100%; height: 100%; display: block; }

  .evo {
    width: var(--stage-w);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--card); border-radius: 14px; padding: 4px 6px; box-shadow: var(--shadow);
  }
  .evo canvas { width: calc((var(--stage-w) - 24px) / 11); height: calc((var(--stage-w) - 24px) / 11); display: block; }

  .overlay {
    position: absolute; inset: 0; z-index: 2; border-radius: 22px;
    display: none; align-items: center; justify-content: center;
    background: rgba(59, 42, 74, .55); backdrop-filter: blur(3px);
  }
  .overlay.show { display: flex; animation: fade .3s ease; }
  @keyframes fade { from { opacity: 0 } to { opacity: 1 } }
  .panel {
    background: #fff; border-radius: 22px; padding: 22px 26px; text-align: center;
    box-shadow: 0 12px 40px rgba(0,0,0,.25); width: 78%;
    animation: pop .35s cubic-bezier(.2,1.6,.4,1);
  }
  @keyframes pop { from { transform: scale(.6) } to { transform: scale(1) } }
  .panel h2 { margin: 0 0 6px; font-size: 26px; color: var(--accent); }
  .panel .final { font-size: 40px; font-weight: 800; margin: 4px 0; font-variant-numeric: tabular-nums; }
  .panel .best { font-size: 14px; opacity: .7; }
  .panel .newbest { color: #ff9900; font-weight: 800; margin-top: 4px; display: none; }
  .panel .newbest.show { display: block; animation: pop .5s ease infinite alternate; }
  .btn {
    margin-top: 16px; border: 0; cursor: pointer;
    font: inherit; font-weight: 800; font-size: 17px; color: #fff;
    padding: 12px 26px; border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    box-shadow: 0 6px 0 #d94470, 0 10px 20px rgba(255,94,138,.35);
    transition: transform .08s;
  }
  .btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #d94470; }

.audio-settings { width: var(--stage-w); font-size: 12px; }
.audio-settings summary { cursor: pointer; text-align: center; }
.audio-controls { display: flex; gap: 8px; padding: 8px; background: var(--card); border-radius: 12px; }
.audio-controls label { flex: 1; min-width: 0; }
.audio-controls input { width: 100%; accent-color: var(--accent); }
.app { --stage-w: min(420px, calc((100vw - 24px) * var(--stage-width-ratio, 0.7)), calc((100dvh - 260px) * 0.735294)); }
.stage { --stage-w: min(420px, calc((100vw - 24px) * var(--stage-width-ratio, 0.7)), calc((100dvh - 260px) * 0.735294)); }

/* Phone layout: reserve space for the visible character, not its transparent canvas. */
@media (max-width: 600px) and (orientation: portrait) {
  html, body { overflow-x: hidden; overflow-y: auto; }
  .app {
    --stage-w: min(420px, calc((100vw - 24px) * 0.805));
    height: auto;
    min-height: 100dvh;
    justify-content: flex-start;
    gap: 12px;
    padding: max(16px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
  }
  .stage { --stage-w: min(420px, calc((100vw - 24px) * 0.805)); flex-shrink: 0; }
  .title { font-size: clamp(23px, 6.2vw, 32px); letter-spacing: .02em; white-space: nowrap; }
  .hud { row-gap: 12px; }
  .card .label { font-size: 12px; }
  .evo {
    width: min(420px, calc(100vw - 24px));
    padding: 8px 6px;
  }
  .evo canvas {
    width: calc((min(420px, 100vw - 24px) - 16px) / 11);
    height: calc((min(420px, 100vw - 24px) - 16px) / 11);
  }
  .audio-settings { width: min(420px, calc(100vw - 24px)); font-size: 16px; }
  .audio-settings summary { min-height: 44px; line-height: 44px; font-weight: 800; }
  .audio-controls { padding: 12px; gap: 12px; }
  .audio-controls input { min-height: 32px; }
}

.card .try-count { font-size: 13px; font-weight: 800; color: #bb4560; line-height: 1.3; }
.panel .final { font-size: clamp(19px, 5vw, 28px); overflow-wrap: anywhere; }

/* Compact header with an overlaid audio panel. */
.app { height: 100dvh; min-height: 0; padding-top: max(6px, env(safe-area-inset-top)); gap: 6px; }
.audio-settings { position: relative; top: auto; left: auto; flex: 0 0 44px; width: auto; z-index: 10; font-size: 16px; }
.audio-settings summary { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; min-height: 44px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); list-style: none; color: var(--ink); }
.audio-settings summary::-webkit-details-marker { display: none; }
.audio-settings summary:focus-visible { outline: 3px solid var(--accent); }
.settings-panel { position: absolute; top: 100%; right: 0; left: auto; width: min(320px, calc(100vw - 24px)); max-height: calc(100dvh - 64px); overflow-y: auto; margin-top: 6px; padding: 16px; background: #fff8f3; border-radius: 16px; box-shadow: var(--shadow); }
.settings-panel .audio-controls { flex-direction: column; background: none; padding: 10px 0 0; }
.settings-panel input { min-height: 32px; }
.touch-pad { width: min(560px, 100%); min-height: 28px; flex: 0 0 28px; touch-action: none; cursor: pointer; display: flex; align-items: center; justify-content: center; border-radius: 16px; background: rgba(255,255,255,.2); color: #73516a; }
.touch-pad span { pointer-events: none; font-size: 12px; }

.title-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; min-width: 0; }
.title-row .title { flex: 1; min-width: 0; font-size: clamp(18px, 5.2vw, 27px); white-space: nowrap; letter-spacing: 0; }
.hud { row-gap: 6px; flex-shrink: 0; }
.evo { flex-shrink: 0; touch-action: none; cursor: pointer; }
.evo, .evo *, .touch-pad, .touch-pad * { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.evo canvas { pointer-events: none; }

.title-screen { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(16px, 4vh, 36px); padding: max(20px, env(safe-area-inset-top)) 18px max(20px, env(safe-area-inset-bottom)); background: radial-gradient(ellipse at 50% 35%, #fff8e7, transparent 70%), linear-gradient(155deg, var(--bg1), var(--bg2)); overflow-y: auto; text-align: center; }
.title-screen[hidden], .title-screen [hidden] { display: none; }
.title-logo { display: block; width: min(880px, 94vw); max-height: 46dvh; object-fit: contain; filter: drop-shadow(0 12px 14px rgba(130,60,60,.15)); }
.start-button { flex-shrink: 0; border: 0; border-radius: 999px; padding: 14px 28px; background: rgba(255,255,255,.75); color: var(--ink); font: 800 clamp(18px, 4.5vw, 25px) "M PLUS Rounded 1c", sans-serif; cursor: pointer; animation: start-float 2.2s ease-in-out infinite; }
.start-button:disabled { animation: none; opacity: .65; cursor: wait; }
.start-button:focus-visible { outline: 3px solid var(--accent); outline-offset: 5px; }
.title-screen p { margin: 0; font-size: clamp(12px, 3.2vw, 16px); }
@keyframes start-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .start-button { animation: none; } }

#titleSettings { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); z-index: 2; }
.logo-start { border: 0; padding: 0; background: transparent; cursor: pointer; max-width: 100%; flex-shrink: 0; }
.logo-start:disabled { cursor: wait; }
.logo-start:focus-visible { outline: 3px solid var(--accent); border-radius: 16px; }
.logo-start .title-logo { max-width: 100%; }

.rank-link { font: inherit; color: var(--ink); background: rgba(255,255,255,.7); border: 1px solid #e8bcc7; border-radius: 999px; padding: 8px 16px; cursor: pointer; }
#rankingDialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 20px; border: 0; border-radius: 22px; background: #fff8f3; color: var(--ink); box-shadow: var(--shadow); }
#rankingDialog::backdrop { background: rgba(59,42,74,.55); }
.rank-heading { display: flex; align-items: center; justify-content: space-between; }
.rank-heading h2 { margin: 0; }
.rank-heading button { font-size: 26px; min-width: 44px; min-height: 44px; border: 0; background: transparent; cursor: pointer; }
.rank-local, #rankingNotice { font-size: 12px; opacity: .75; }
#rankingForm { padding: 12px; background: white; border-radius: 14px; }
#rankingForm label, #rankingNotice { display: block; margin-top: 8px; }
#rankingName { width: 100%; box-sizing: border-box; padding: 8px; font: 800 24px monospace; letter-spacing: .15em; border: 2px solid #e8bcc7; border-radius: 8px; user-select: text; -webkit-user-select: text; }
.rank-tabs { display: flex; gap: 8px; margin: 16px 0 8px; }
.rank-tabs button { flex: 1; padding: 10px; border: 0; border-radius: 10px; font: inherit; cursor: pointer; }
.rank-tabs button[aria-pressed="true"] { background: var(--accent); color: white; }
.rank-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rank-table th, .rank-table td { text-align: left; padding: 9px 3px; border-bottom: 1px solid #eedbe0; }
.rank-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.rank-table tr:nth-child(-n+3) td:first-child { color: #bf7600; font-weight: 800; }

/* Keep the stack visible after game over. */
.overlay { background: rgba(59,42,74,.12); backdrop-filter: none; align-items: flex-start; padding-top: 10px; }
.overlay .panel { width: 92%; padding: 12px; background: rgba(255,255,255,.88); }
.overlay .panel h2 { font-size: 22px; }
.overlay .panel .btn { margin-top: 8px; padding: 8px 18px; }


/* インストール後の画面端・ホームインジケーター用の余白。 */
.app { padding-bottom: max(8px, env(safe-area-inset-bottom)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
.title-screen { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.title-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; flex-shrink: 0; }
#installDialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 20px; border: 0; border-radius: 22px; background: #fff8f3; color: var(--ink); }
#installDialog::backdrop { background: rgba(59,42,74,.55); }
#installHeading { font-size: 20px; }
#installHelp { line-height: 1.8; }
.install-note { font-size: 13px; line-height: 1.6; }

/* 縦持ちのホーム画面起動のみ。余った高さは下部の操作面に使う。 */
.app.standalone-phone { justify-content: flex-start; }
.standalone-phone .stage { flex-shrink: 0; }
.standalone-phone .touch-pad { flex: 1 0 28px; }
