:root {
  --bg: #f1f8ec;
  --bg2: #e6f3ee;
  --surface: rgba(255, 255, 255, 0.82);
  --ink: #223038;
  --ink-soft: #5b6b73;
  --line: rgba(34, 48, 56, 0.10);
  --teal: #2f9e6b;
  --teal-dark: #1f7a50;
  --rose: #ff4f86;
  --amber: #ffab1f;
  --sky: #2f8fff;
  --shadow: 0 10px 30px rgba(40, 60, 70, 0.12);
  --radius: 18px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); }
body {
  font-family: "Avenir Next", "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}

#app { position: fixed; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(60% 50% at 15% 10%, rgba(255, 190, 210, 0.45), transparent 60%),
    radial-gradient(50% 45% at 90% 15%, rgba(255, 220, 150, 0.45), transparent 60%),
    radial-gradient(60% 55% at 70% 95%, rgba(170, 210, 255, 0.55), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}

.screen {
  position: absolute; inset: 0; z-index: 1; display: none; flex-direction: column;
  padding: calc(12px + var(--sat)) calc(12px + var(--sar)) calc(12px + var(--sab)) calc(12px + var(--sal));
}
.screen.active { display: flex; }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: 16px; min-height: 48px; min-width: 48px; padding: 0 18px;
  border-radius: 999px; cursor: pointer; box-shadow: 0 2px 8px rgba(40, 60, 70, 0.08);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform 0.08s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: linear-gradient(135deg, #2f9e6b, #6fd29a); color: #fff; border-color: transparent; box-shadow: 0 8px 20px rgba(47, 158, 107, 0.35); }
.btn-accent { background: linear-gradient(135deg, #ffb42e, #ff7a59); color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn-small { min-height: 40px; font-size: 14px; padding: 0 14px; }

/* Boot */
#screen-boot { align-items: center; justify-content: center; }
.boot-card { text-align: center; color: var(--ink-soft); }
.boot-bloom { position: relative; width: 84px; height: 84px; margin: 0 auto 14px; animation: spin 6s linear infinite; }
.boot-bloom i {
  position: absolute; left: 50%; top: 50%; width: 30px; height: 46px; margin: -46px 0 0 -15px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; transform-origin: 50% 100%;
  background: linear-gradient(180deg, rgba(255, 120, 160, 0.9), rgba(255, 190, 210, 0.7));
  animation: petal 1.6s ease-in-out infinite;
}
.boot-bloom i:nth-child(1) { transform: rotate(0deg); }
.boot-bloom i:nth-child(2) { transform: rotate(60deg); background: linear-gradient(180deg, rgba(255, 180, 60, 0.9), rgba(255, 225, 160, 0.7)); }
.boot-bloom i:nth-child(3) { transform: rotate(120deg); background: linear-gradient(180deg, rgba(80, 160, 255, 0.9), rgba(190, 220, 255, 0.7)); }
.boot-bloom i:nth-child(4) { transform: rotate(180deg); }
.boot-bloom i:nth-child(5) { transform: rotate(240deg); background: linear-gradient(180deg, rgba(255, 180, 60, 0.9), rgba(255, 225, 160, 0.7)); }
.boot-bloom i:nth-child(6) { transform: rotate(300deg); background: linear-gradient(180deg, rgba(80, 160, 255, 0.9), rgba(190, 220, 255, 0.7)); }
@keyframes petal { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
.boot-bar { width: 160px; height: 6px; margin: 12px auto 0; border-radius: 3px; background: rgba(0, 0, 0, 0.08); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 20%; background: var(--teal); transition: width 0.25s ease; }

/* Title */
#screen-title { align-items: center; justify-content: center; }
.title-card {
  width: min(480px, 100%); text-align: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: 28px; padding: 22px 22px 18px; box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
.title-art { width: 100%; max-width: 360px; height: auto; aspect-ratio: 16 / 9; border-radius: 18px; display: block; margin: 0 auto 10px; }
h1 { margin: 6px 0 2px; font-size: clamp(30px, 6vw, 40px); letter-spacing: 0.02em; font-weight: 800; }
.tagline { margin: 0 0 16px; color: var(--ink-soft); font-size: 15px; }
.title-actions { display: flex; flex-direction: column; gap: 10px; }
.title-actions .btn { width: 100%; min-height: 52px; font-size: 17px; }
.title-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 8px; }
.progress-pill { display: inline-block; font-size: 13px; color: var(--ink-soft); background: rgba(0, 0, 0, 0.05); padding: 6px 12px; border-radius: 999px; }

/* Bars */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.bar h2 { margin: 0; font-size: 18px; }

/* Level grid */
.level-grid {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; padding: 4px 2px 12px; align-content: start;
}
.level-btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
  border-radius: 14px; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 2px 6px rgba(40, 60, 70, 0.06);
}
.level-btn b { font-size: 18px; }
.level-btn small { font-size: 11px; color: #d9a400; letter-spacing: 1px; min-height: 14px; }
.level-btn.locked { opacity: 0.45; cursor: default; }
.level-btn.locked small { color: var(--ink-soft); }
.level-btn.current { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(47, 158, 107, 0.35); }

/* Play */
#screen-play { padding-bottom: calc(8px + var(--sab)); }
.hud { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.hud-center { flex: 1; min-width: 0; text-align: center; line-height: 1.15; }
.hud-center b { display: block; font-size: 18px; }
.hud-center small { color: var(--ink-soft); font-size: 12.5px; }
.hud-flowers { font-size: 14px; font-weight: 700; color: var(--teal-dark); background: rgba(47, 158, 107, 0.12); padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
#board-wrap { flex: 1; min-height: 0; position: relative; margin: 6px 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.controls { display: flex; gap: 8px; justify-content: center; }
.controls .btn { flex: 1; max-width: 160px; }

/* Landscape phones: put controls to the sides so the board keeps its height */
@media (orientation: landscape) and (max-height: 520px) {
  #screen-play { flex-direction: row; align-items: stretch; gap: 8px; }
  .hud { flex-direction: column; width: 120px; justify-content: center; }
  .hud-center b { font-size: 16px; }
  #board-wrap { margin: 0; }
  .controls { flex-direction: column; width: 110px; justify-content: center; }
  .controls .btn { max-width: none; padding: 0 8px; }
  #screen-title { flex-direction: row; }
  .title-card { padding: 12px 16px; }
  .title-art { max-width: 200px; margin-bottom: 4px; }
  h1 { font-size: 24px; margin: 0; }
  .tagline { margin-bottom: 8px; font-size: 13px; }
  .title-actions { flex-direction: row; }
  .title-actions .btn { min-height: 44px; font-size: 15px; }
  .title-foot { margin-top: 8px; }
}

/* Modal */
.modal { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(40, 55, 65, 0.28); backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.modal-card { width: min(420px, 100%); background: #fff; border-radius: 22px; padding: 20px 20px 16px; box-shadow: var(--shadow); text-align: center; max-height: calc(100% - 24px); overflow-y: auto; }
.modal-card h3 { margin: 0 0 8px; font-size: 22px; }
.modal-card p { margin: 6px 0; color: var(--ink-soft); }
.stars { font-size: 34px; letter-spacing: 4px; color: #e6b400; margin: 4px 0 6px; }
.stars .dim { color: rgba(0, 0, 0, 0.15); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.modal-actions .btn { flex: 1 1 120px; }
.howto { text-align: left; display: grid; gap: 10px; margin-top: 6px; }
.howto div { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; }
.howto canvas { width: 44px; height: 44px; border-radius: 10px; background: rgba(0, 0, 0, 0.04); }
.howto p { margin: 0; color: var(--ink); font-size: 14.5px; }

.toast { position: absolute; left: 50%; bottom: calc(90px + var(--sab)); transform: translateX(-50%); z-index: 6; background: rgba(34, 48, 56, 0.9); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90%; text-align: center; }
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .boot-bloom, .boot-bloom i { animation: none; }
}
