* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #e9faff;
  overflow: hidden;
}

#game-wrap {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) 375px minmax(230px, 1fr);
  gap: 28px;
  padding: 0 28px;
  align-items: center;
  justify-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 14% 18%, rgba(255,255,255,.82) 0 70px, transparent 72px),
    radial-gradient(circle at 87% 72%, rgba(255,255,255,.62) 0 94px, transparent 96px),
    radial-gradient(circle at 52% 88%, rgba(255,255,255,.38) 0 120px, transparent 124px),
    linear-gradient(135deg, #dff8ff, #fff3c8 48%, #ffd6ed);
}

#game {
  touch-action: none;
  position: relative;
  width: 375px;
  height: 667px;
  overflow: hidden;
  transform-origin: center center;
  background: linear-gradient(180deg, #8ee8ff 0%, #fff5b8 55%, #ffd1ec 100%);
  box-shadow: 0 10px 34px rgba(0,0,0,.18);
}

#game::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.65) 0 42px, transparent 44px),
    radial-gradient(circle at 82% 28%, rgba(255,255,255,.55) 0 52px, transparent 54px),
    radial-gradient(circle at 50% 76%, rgba(255,255,255,.45) 0 70px, transparent 72px);
  pointer-events: none;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  background: rgba(255,255,255,.88);
  color: #333;
  padding: 10px 14px;
  border-radius: 16px;
  font-weight: bold;
  font-size: 13px;
  line-height: 1.8;
  box-shadow: 0 6px 16px rgba(0,0,0,.16);
}

.title {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  background: #ff63ad;
  color: #fff;
  padding: 10px 15px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 6px 16px rgba(0,0,0,.18);
}

#player {
  position: absolute;
  bottom: 24px;
  left: 50%;
  width: 74px;
  height: 74px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: #fff7c7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
  z-index: 5;
}

#player::after,
#tartSide::after { content: attr(data-fallback); }

#player img,
.worry img,
.heal img,
#tartSide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.worry {
  position: absolute;
  width: 45px;
  min-height: 50px;
  padding: 5px;
  border-radius: 50%;
  background: linear-gradient(135deg, #9a9cdf, #bbade9);
  border: 3px solid rgba(255,255,255,.85);
  color: #fff;
  text-align: center;
  align-items: center;
  font-size: 12px;
  font-weight: bold;
  box-shadow: 0 8px 16px rgba(0,0,0,.22);
  z-index: 3;
}

.heal {
  position: absolute;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  animation: healPulse .8s infinite alternate;
  z-index: 3;
}

@keyframes healPulse {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}

#message {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: 337px;
  padding: 26px 20px;
  background: rgba(255,255,255,.95);
  border-radius: 24px;
  text-align: center;
  z-index: 20;
  color: #333;
  box-shadow: 0 12px 30px rgba(0,0,0,.22);
}

#message h1 {
  margin-top: 0;
  color: #ff5fa2;
  font-size: 32px;
}

button {
  border: none;
  padding: 12px 22px;
  border-radius: 999px;
  background: #ffde59;
  color: #333;
  font-weight: bold;
  cursor: pointer;
  margin-top: 12px;
  box-shadow: 0 5px 0 #e5b800;
}
button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #e5b800;
}

.mobile-controls { display: none; }

#comboText {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  font-size: 38px;
  font-weight: 900;
  color: #ff5fa2;
  text-shadow: 4px 4px 0 #fff;
  z-index: 25;
  opacity: 0;
  pointer-events: none;
}
#comboText.show { animation: comboPop .45s ease; }
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  45% { opacity: 1; transform: translate(-50%, -50%) scale(1.35); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

#keiCutin {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -50%) scale(.8);
  background: #fff;
  color: #333;
  padding: 16px 22px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: bold;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 10px 25px rgba(0,0,0,.25);
  white-space: nowrap;
}
#keiCutin.show { animation: cutin .95s ease; }
@keyframes cutin {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.2); }
}

.side-panel {
  width: 100%;
  max-width: 280px;
  height: 667px;
  position: relative;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
  overflow: visible;
}
.left-panel { justify-self: end; align-items: flex-end; }
.right-panel { justify-self: start; align-items: flex-start; }

.side-title {
  background: #ff63ad;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(0,0,0,.16);
}
.side-card {
  max-width: 220px;
  background: rgba(255,255,255,.82);
  color: #333;
  padding: 14px 16px;
  border-radius: 18px;
  font-weight: bold;
  line-height: 1.6;
  box-shadow: 0 8px 22px rgba(0,0,0,.14);
  font-size: 14px;
}
.side-howto { border: 1px solid rgba(255,190,45,.55); }

.tart-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
#tartSide {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 8px 22px rgba(0,0,0,.18);
  padding: 8px;
  animation: tartFloat 1.8s infinite ease-in-out;
}
#tartName {
  width: 86px;
  text-align: center;
  color: #333;
  font-weight: bold;
  font-size: 13px;
}
#tartBubble {
  max-width: 220px;
  background: #fff;
  color: #333;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: bold;
  line-height: 1.6;
  box-shadow: 0 8px 22px rgba(0,0,0,.16);
  white-space: normal;
}
@keyframes tartFloat {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

#rankingPanel {
  width: 100%;
  max-width: 220px;
  margin-top: 22px;
  background: rgba(255,255,255,.9);
  color: #333;
  border-radius: 20px;
  padding: 16px 18px;
  z-index: 16;
  box-shadow: 0 8px 22px rgba(0,0,0,.14);
  font-size: 13px;
  pointer-events: auto;
}
#rankingPanel h3 {
  margin: 0 0 10px;
  color: #ff5fa2;
  font-size: 18px;
  text-align: center;
}
#rankingList {
  margin: 0;
  padding-left: 20px;
}
#rankingList li { margin-bottom: 5px; }
.ranking-note {
  margin: 10px 0 0;
  font-size: 11px;
  color: #555;
  text-align: center;
}

.result-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.pop {
  position: absolute;
  font-size: 22px;
  font-weight: 900;
  color: #ff5fa2;
  text-shadow: 2px 2px 0 #fff;
  z-index: 40;
  pointer-events: none;
  animation: popUp .7s ease forwards;
}
@keyframes popUp {
  from { opacity: 1; transform: translateY(0) scale(.7); }
  to { opacity: 0; transform: translateY(-45px) scale(1.3); }
}

.name-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.35);
  z-index: 999;
}
.name-modal.show { display: flex; }
.name-modal-box {
  width: min(90vw, 340px);
  background: #fff;
  color: #333;
  border-radius: 24px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0,0,0,.25);
}
.name-modal-box h2 {
  margin-top: 0;
  color: #ff5fa2;
}
#rankingNameInput {
  width: 100%;
  padding: 14px;
  border: 2px solid #ffb6d9;
  border-radius: 14px;
  font-size: 16px;
  text-align: center;
  outline: none;
}
.name-modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

@media (max-width: 900px) {
  #game-wrap {
    grid-template-columns: 1fr 375px 1fr;
    gap: 14px;
    padding: 0 10px;
  }
  .side-panel {
    max-width: 190px;
    padding: 12px;
  }
  .left-panel .side-card,
  .side-howto { display: none; }
}

@media (max-width: 767px), (pointer: coarse) {
  body { background: #dff8ff; }
  #game-wrap {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    gap: 0;
  }
  .left-panel { display: none; }
  .right-panel {
    position: fixed;
    right: 6px;
    bottom: 96px;
    width: 52px;
    height: auto;
    padding: 0;
    display: flex;
    align-items: center;
    z-index: 40;
  }
  .tart-area { align-items: center; gap: 4px; }
  #tartSide {
    width: 46px;
    height: 46px;
    padding: 5px;
  }
  #tartName { display: none; }
  #tartBubble {
    position: absolute;
    bottom: 0px;
    width: 130px;
    max-width: 132px;
    padding: 8px 10px;
    font-size: 10px;
    line-height: 1.4;
    right: 0px;
  }
  .mobile-controls {
    display: flex;
    position: absolute;
    left: 0;
    bottom: 30px;
    width: 100%;
    justify-content: space-between;
    padding: 0 18px;
    z-index: 12;
    pointer-events: none;
  }
  .mobile-controls button {
    width: 72px;
    height: 48px;
    pointer-events: auto;
    font-size: 20px;
  }
  #player { bottom: 72px; }
  #message {
    width: 330px;
    top: 42%;
    padding: 24px 18px;
  }
  #message h1 { font-size: 30px; }
  .hud {
    top: 10px;
    left: 10px;
    font-size: 12px;
    padding: 8px 12px;
  }
  .title {
    top: 10px;
    right: 10px;
    font-size: 12px;
    padding: 9px 13px;
  }
}

@media (max-width: 430px) {
  .right-panel { right: 4px; bottom: 94px; }
}


/* =========================
   PC版：ゲーム画面を拡大させない
   ※ JSのscaleによるPCレイアウト崩れ対策
========================= */
@media (min-width: 768px) and (min-height: 667px) {
  #game {
    transform: none !important;
  }

  #game-wrap {
    grid-template-columns: minmax(260px, 1fr) 375px minmax(260px, 1fr);
    gap: 48px;
    padding: 0 48px;
  }

  .side-panel {
    max-width: 260px;
  }

  .left-panel {
    justify-self: end;
  }

  .right-panel {
    justify-self: start;
  }
}

/* 横幅が広いPCでは余白をより安定させる */
@media (min-width: 1200px) {
  #game-wrap {
    grid-template-columns: minmax(300px, 1fr) 375px minmax(300px, 1fr);
    gap: 64px;
    padding: 0 64px;
  }

  .side-panel {
    max-width: 280px;
  }
}

/* タブレット幅ではサイドパネルを控えめにする */
@media (min-width: 768px) and (max-width: 1100px) {
  #game-wrap {
    grid-template-columns: minmax(160px, 1fr) 375px minmax(160px, 1fr);
    gap: 18px;
    padding: 0 18px;
  }

  .side-panel {
    max-width: 170px;
    padding: 10px;
  }

  .side-card,
  .side-title {
    font-size: 12px;
  }

}

/* =========================
   SP：ランキングをゲーム下に必ず表示
========================= */
@media (max-width: 767px), (pointer: coarse) {
  body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  #game-wrap {
    height: auto !important;
    min-height: 100vh !important;
    overflow: visible !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: center !important;
    padding: 12px 0 32px !important;
  }

  #game {
    flex: 0 0 auto !important;
  }

  .right-panel {
    position: static !important;
    width:100%;
    max-width:375px;
    margin:0 auto;
    height: auto !important;
    padding: 12px 0 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    z-index: 1 !important;
  }

  .tart-area {
    display: none !important;
  }

  #rankingPanel {
    display: block !important;
    position: static !important;
    width:100%;
    max-width:340px;
    margin:20px auto;
    padding: 16px 18px !important;
    background: rgba(255,255,255,.96) !important;
    border-radius: 20px !important;
    box-shadow: 0 8px 22px rgba(0,0,0,.14) !important;
    color: #333 !important;
    font-size: 13px !important;
  }

  #rankingPanel h3 {
    margin: 0 0 10px !important;
    font-size: 18px !important;
    color: #ff5fa2 !important;
    text-align: center !important;
  }

  #rankingList {
    margin: 0 !important;
    padding-left: 20px !important;
    font-size: 13px !important;
  }

  #rankingList li {
    margin-bottom: 6px !important;
  }
}

@media (max-width:767px){

  #game{
    transform:none !important;
    margin:0 auto;
  }

  #game-wrap{
    width:100%;
    align-items:center;
  }

}

#rankingGuide {
  display: none;
}

@media (max-width: 767px), (pointer: coarse) {
  #rankingGuide {
    display: block;
    text-align: center;
    position: absolute;
    left: 50%;
    bottom: 25px;
    transform: translateX(-50%);
    z-index: 30;
    background: rgba(255,255,255,.94);
    color: #ff5fa2;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 900;
    box-shadow: 0 6px 16px rgba(0,0,0,.18);
    animation: guideBounce 1.2s infinite ease-in-out;
    pointer-events: none;
    white-space: nowrap;
  }
}

@keyframes guideBounce {
  0%, 100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(5px);
  }
}

.mobile-controls,
.mobile-controls button {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}