:root {
  color-scheme: light;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background: #f8f3e9;
  color: #455755;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; width: auto; height: auto; overflow: hidden; }
button { font: inherit; cursor: pointer; }
button { -webkit-touch-callout: none; }
button:focus-visible { outline: 4px solid #457e82; outline-offset: 3px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.game-shell {
  --sky: #d9f4ed; --horizon: #f6f3de; --hill: #c5e8ca;
  --ground: #a9d9b4; --accent: #e98069; --ink: #455755;
  --slot-size: clamp(94px, min(18vw, 36dvh), 168px);
  --tray-size: clamp(75px, min(14.5vw, 29dvh), 124px);
  position: absolute; inset: 0; width: auto; height: auto; min-height: 0;
  display: flex; flex-direction: column; overflow: hidden;
  background: #f8f3e9; color: var(--ink); user-select: none; -webkit-user-select: none;
}
.topbar {
  position: relative; z-index: 3; flex: 0 0 clamp(49px, 12dvh, 65px);
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center; gap: 10px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: #fffaf0; box-shadow: 0 2px 14px #6576611c;
}
.brand { min-width: 0; display: flex; align-items: center; gap: 9px; }
.navigation { min-width: 0; display: flex; align-items: center; gap: 14px; }
.back-button, .rotate-back-button { display: flex; justify-content: center; align-items: center; gap: 3px; flex-shrink: 0; min-width: 90px; min-height: 44px; padding: 6px 12px; border: 2px solid #e7dfcd; border-radius: 18px; color: var(--ink); background: #fffefa; font-size: 16px; font-weight: 800; }
.back-button svg { width: 18px; height: 18px; }
.back-button:active, .rotate-back-button:active { background: #ece6d7; }
.brand-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(14px, 2.3vw, 22px); font-weight: 800; letter-spacing: .035em; }
.brand-mark { position: relative; display: block; flex: 0 0 25px; width: 25px; height: 25px; transform: rotate(-12deg); }
.brand-mark i { position: absolute; width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.brand-mark i:nth-child(1) { left: 7px; top: 0; }.brand-mark i:nth-child(2) { right: 0; top: 7px; }
.brand-mark i:nth-child(3) { left: 7px; bottom: 0; }.brand-mark i:nth-child(4) { left: 0; top: 7px; }
.brand-mark i:nth-child(5) { left: 8px; top: 8px; width: 9px; height: 9px; background: #ffde99; }
.progress { display: flex; align-items: center; justify-content: center; gap: clamp(8px, 1.6vw, 17px); padding: 4px; }
.pip { display: block; width: clamp(13px, 2.3vw, 21px); height: clamp(13px, 2.3vw, 21px); border: 2.5px solid #b9c9bc; background: #f0f0e5; border-radius: 50%; transition: background .2s, transform .35s, border-color .2s; }
.pip.is-done { background: var(--accent); border-color: #fffaf0; box-shadow: 0 0 0 2px var(--accent); transform: scale(1.12); }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 13px; }
.stage-number { white-space: nowrap; font-size: clamp(12px, 1.9vw, 17px); font-weight: 800; opacity: .72; font-variant-numeric: tabular-nums; }
.sound-button { flex: 0 0 clamp(44px, 8dvh, 54px); width: clamp(44px, 8dvh, 54px); height: clamp(44px, 8dvh, 54px); padding: 8px; color: var(--ink); background: #f5efdf; border: 0; border-radius: 50%; display: grid; place-items: center; }
.sound-button svg { width: 100%; height: 100%; }.mute-slash { display: none; }.sound-button.is-muted .mute-slash { display: block; }

.playfield {
  position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden;
  background: linear-gradient(180deg, var(--sky) 0%, var(--horizon) 100%);
  background-size: cover; background-position: center;
}
.landscape { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.has-background .landscape { opacity: .18; }
.sun { position: absolute; top: -24%; right: 11%; width: min(16vw, 22dvh); aspect-ratio: 1; border-radius: 50%; background: #fffcef88; box-shadow: 0 0 0 24px #fffcef2b, 0 0 0 52px #fffcef18; }
.hill { position: absolute; width: 120%; height: 50%; border-radius: 50% 50% 0 0; }
.hill-back { bottom: -23%; left: -28%; transform: rotate(6deg); background: var(--hill); opacity: .75; }
.hill-front { bottom: -34%; right: -37%; transform: rotate(-4deg); background: var(--ground); opacity: .72; }
.slots, .sparkles { position: absolute; inset: 0; pointer-events: none; }
.slot {
  position: absolute; width: var(--slot-size); height: var(--slot-size);
  transform: translate(-50%, -50%); padding: 8px;
  border: 3px dashed #ffffffc7; border-radius: 33%; background: #fffdf573;
  box-shadow: 0 10px 25px #59765b19, inset 0 0 0 2px #6d8f7724;
  display: grid; place-items: center; pointer-events: auto; touch-action: manipulation;
  transition: background .18s, border-color .18s, box-shadow .18s, scale .18s;
}
.slot::after { content: ""; position: absolute; width: 65%; height: 8%; bottom: -9%; border-radius: 50%; background: #506d5430; filter: blur(5px); }
.silhouette { width: 94%; height: 94%; object-fit: contain; pointer-events: none; filter: brightness(0); opacity: .26; }
.slot.is-near, .slot.is-guided { border-color: var(--accent); background: #fffdf5b8; box-shadow: 0 0 0 7px #fffaf081, 0 10px 27px #59765b25; scale: 1.045; }
.slot.is-filled { border-color: transparent; background: transparent; box-shadow: none; opacity: 1; }
.slot.is-filled .silhouette { display: none; }
.placed-image { position: absolute; inset: 3%; width: 94%; height: 94%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 9px 4px #526a6030); animation: settle .4s cubic-bezier(.21,1.4,.36,1) both; }
@keyframes settle { from { transform: scale(.72); opacity: .55; } 55% { transform: scale(1.12); opacity: 1; } to { transform: scale(1); opacity: 1; } }

.tray {
  position: relative; z-index: 2; flex: 0 0 clamp(112px, 32dvh, 166px);
  padding: 5px max(12px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: #fffaf0; box-shadow: 0 -5px 23px #536d5a1c; display: grid; place-items: center;
}
.tray::before { content: ""; position: absolute; left: 50%; top: -6px; transform: translateX(-50%); width: 68px; height: 13px; background: #fffaf0; border-radius: 50% 50% 0 0; }
.tray-items { display: flex; justify-content: center; align-items: center; gap: clamp(14px, 4.2vw, 60px); width: 100%; height: 100%; }
.piece {
  flex: 0 0 var(--tray-size); width: var(--tray-size); height: var(--tray-size);
  display: grid; place-items: center; border: 2px solid #ffffff; border-radius: 31%; padding: 8px;
  background: #fffefa; box-shadow: 0 5px 0 #dfdfd0, 0 9px 20px #53675324;
  touch-action: none; transition: transform .18s, box-shadow .18s, opacity .18s; cursor: grab;
}
.piece:active { cursor: grabbing; }
.piece-image { width: 100%; height: 100%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 3px 2px #46644420); }
.piece.is-selected { transform: translateY(-7px); box-shadow: 0 4px 0 var(--accent), 0 0 0 5px #f3bd97a6; }
.piece.is-lifted { opacity: .2; }
.piece.is-used { opacity: 0; pointer-events: none; box-shadow: none; }
.drag-layer { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.drag-ghost { position: absolute; object-fit: contain; transform: translate(-50%, -50%) scale(1.08); filter: drop-shadow(0 15px 8px #3e594744); }
.hint-hand { position: absolute; z-index: 6; width: 39px; height: 47px; opacity: 0; pointer-events: none; filter: drop-shadow(1px 4px 3px #40554a55); }
.hint-hand svg { width: 100%; height: 100%; }
.sparkles i { position: absolute; width: clamp(7px, 1vw, 12px); height: clamp(7px, 1vw, 12px); border-radius: 50%; background: #fff9d7; box-shadow: 0 0 0 2px var(--accent); animation: sparkle .58s ease-out forwards; }
@keyframes sparkle { from { transform: translate(-50%,-50%) scale(.5); opacity: 1; } to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.35); opacity: 0; } }

.stage-party { position: absolute; z-index: 7; left: 50%; top: 43%; transform: translate(-50%, -50%) scale(.7); opacity: 0; pointer-events: none; display: grid; justify-items: center; gap: 9px; padding: 17px 38px 19px; border-radius: 35px; color: var(--ink); background: #fffaf0ed; box-shadow: 0 15px 45px #3a5a4842; }
.stage-party.show { animation: party-in .42s cubic-bezier(.18,1.5,.36,1) forwards; }
.stage-party strong { white-space: nowrap; font-size: clamp(26px, 5vw, 46px); line-height: 1; }
@keyframes party-in { to { opacity: 1; transform: translate(-50%,-50%) scale(1); } }
.party-flower, .finish-flower { position: relative; width: 63px; height: 63px; }
.party-flower i, .finish-flower i { position: absolute; width: 31%; height: 43%; border-radius: 70% 70% 55% 55%; left: 34.5%; top: 0; background: #f0a58d; transform-origin: 50% 116%; }
.party-flower i:nth-child(2), .finish-flower i:nth-child(2) { transform: rotate(72deg); }
.party-flower i:nth-child(3), .finish-flower i:nth-child(3) { transform: rotate(144deg); }
.party-flower i:nth-child(4), .finish-flower i:nth-child(4) { transform: rotate(216deg); }
.party-flower i:nth-child(5), .finish-flower i:nth-child(5) { transform: rotate(288deg); }
.party-flower b, .finish-flower b { position: absolute; z-index: 1; width: 31%; height: 31%; border-radius: 50%; background: #ffe3a4; left: 34.5%; top: 34.5%; }

.finish { position: absolute; z-index: 8; inset: 0; display: grid; place-items: center; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); background: #50695cb9; backdrop-filter: blur(5px); }
.finish[hidden] { display: none; }
.finish-card { width: min(430px, 80vw); max-height: 96%; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: clamp(15px, 3dvh, 27px) 22px; border-radius: 36px; background: #fffaf0; box-shadow: 0 19px 60px #32483d66; text-align: center; animation: finish-in .45s cubic-bezier(.17,1.25,.38,1) both; }
@keyframes finish-in { from { transform: scale(.78); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.finish-flower { width: clamp(57px, 15dvh, 91px); height: clamp(57px, 15dvh, 91px); }
.finish h1 { margin: 7px 0 0; font-size: clamp(28px, 6dvh, 46px); line-height: 1.1; color: var(--ink); }
.finish p { margin: 3px 0 clamp(11px, 2dvh, 21px); font-size: clamp(14px, 3.2dvh, 22px); font-weight: 700; }
.replay-button { display: flex; justify-content: center; align-items: center; gap: 11px; min-width: 210px; min-height: clamp(51px, 11dvh, 68px); padding: 7px 24px; border: 0; border-radius: 100px; background: var(--accent); color: #fff; box-shadow: 0 5px 0 #b66356; font-size: clamp(18px, 3.6dvh, 25px); font-weight: 800; }
.replay-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #b66356; }
.replay-button svg { flex: 0 0 27px; width: 27px; height: 27px; }
.finish-actions { display: flex; flex-direction: column; align-items: stretch; gap: 14px; width: min(300px, 100%); }
.other-button { display: flex; justify-content: center; align-items: center; gap: 11px; min-height: clamp(51px, 11dvh, 68px); padding: 7px 24px; border: 2px solid #ddd5c1; border-radius: 100px; background: #fffefa; color: var(--ink); box-shadow: 0 4px 0 #ded6c4; font-size: clamp(18px, 3.6dvh, 25px); font-weight: 800; }
.other-button svg { flex: 0 0 25px; width: 25px; height: 25px; }
.other-button:active { transform: translateY(3px); box-shadow: 0 1px 0 #ded6c4; }
.is-finished .topbar, .is-finished .playfield, .is-finished .tray { pointer-events: none; }

.rotate-screen { display: none; }
.rotate-back-button { min-height: 50px; min-width: 180px; margin-top: 10px; }

.selection-screen { --ink: #455755; --accent: #e98069; height: 100%; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; background: radial-gradient(ellipse at 15% 3%, #d9f4ed8c, transparent 55%), #f8f3e9; color: var(--ink); user-select: none; -webkit-user-select: none; }
.selection-header { width: min(1040px, 100%); margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 6px max(18px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.selection-header .brand { font-size: 23px; font-weight: 800; letter-spacing: .08em; }
.selection-content { width: min(1040px, 100%); margin: 0 auto; padding: 3px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.selection-content h1 { margin: 5px 0 17px; text-align: center; font-size: clamp(25px, 6vw, 32px); letter-spacing: .07em; }
.theme-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.theme-card { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 158px; min-width: 0; padding: 13px 8px 15px; border: 3px solid #fff; border-radius: 26px; background: linear-gradient(170deg, var(--card-color), #fffefa 85%); color: #455755; box-shadow: 0 4px 0 #dedbcc, 0 9px 22px #506d5413; touch-action: manipulation; }
.theme-card:active { transform: translateY(3px); box-shadow: 0 1px 0 #dedbcc; border-color: var(--card-accent); }
.theme-preview { width: 100%; height: 84px; display: flex; align-items: center; justify-content: center; gap: 1px; pointer-events: none; }
.theme-preview img { width: 32%; height: 84px; object-fit: contain; filter: drop-shadow(0 3px 2px #45575520); }
.theme-preview img:nth-child(2) { transform: translateY(-7px); }
.theme-label { display: block; margin-top: 9px; font-size: clamp(18px, 2.4vw, 22px); line-height: 1.35; font-weight: 800; text-align: center; letter-spacing: .03em; }
.selection-note { margin: 23px 0 0; font-size: 14px; line-height: 1.75; text-align: center; color: #596b62; }
.load-error { min-height: 100%; padding: 32px; display: grid; place-content: center; text-align: center; background: #fffaf0; color: #455755; }
.load-error strong { font-size: 22px; }.load-error p { line-height: 1.7; }

/* 縦向きでもゲーム本体を表示する。向き変更を強制する全画面案内は出さない。 */
@media (orientation: portrait) and (pointer: coarse) {
  .game-shell {
    --slot-size: clamp(84px, 25vw, 110px);
    --tray-size: clamp(72px, 22vw, 96px);
  }
  .topbar { flex-basis: clamp(56px, 8dvh, 68px); gap: 6px; }
  .navigation { gap: 7px; }
  .back-button { min-width: 78px; min-height: 42px; padding: 5px 8px; }
  .brand-title { font-size: clamp(13px, 3.8vw, 18px); }
  .progress { gap: clamp(5px, 1.7vw, 9px); }
  .pip { width: clamp(12px, 3.8vw, 17px); height: clamp(12px, 3.8vw, 17px); }
  .stage-number { font-size: clamp(11px, 3.3vw, 14px); }
  .sound-button { flex-basis: 44px; width: 44px; height: 44px; }
  .tray { flex-basis: clamp(126px, 19dvh, 166px); }
  .tray-items { gap: clamp(8px, 3vw, 16px); }
}
@media (max-width: 700px) {
  .navigation { gap: 8px; }
  .topbar .brand-mark { display: none; }
  .top-actions { gap: 7px; }
  .back-button { min-width: 84px; padding: 5px 9px; }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
  .theme-card { min-height: 143px; padding: 10px 6px 12px; }
  .theme-preview, .theme-preview img { height: 64px; }
  .theme-label { font-size: 19px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .selection-header { padding-top: 6px; padding-bottom: 0; }
  .selection-header .brand { font-size: 19px; }
  .selection-content h1 { font-size: 23px; margin: 1px 0 11px; }
  .theme-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .theme-card { min-height: 120px; padding: 7px 5px 10px; border-radius: 21px; }
  .theme-preview, .theme-preview img { height: 53px; }
  .theme-label { font-size: 17px; margin-top: 5px; }
  .selection-note { margin-top: 16px; }
}
@media (max-height: 350px) and (orientation: landscape) {
  .topbar { flex-basis: 46px; }.tray { flex-basis: 104px; }
  .game-shell { --slot-size: clamp(83px, min(18vw, 36dvh), 122px); --tray-size: clamp(70px, min(14vw, 27dvh), 92px); }
  .finish-card { padding: 9px 20px; }.finish p { margin-bottom: 8px; }
  .finish-flower { width: 48px; height: 48px; }
  .finish-actions { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
