/* =========================================================
   Mental Tetris - Clean Style CSS
   PC / Tablet / SP layout cleaned
========================================================= */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; touch-action: none; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #fff;
  background:
    radial-gradient(
      circle at top,
      #8ddcff 0%,
      #4f8cff 45%,
      #183c7d 100%
    );
}
body::after {
  content:""; position: fixed; inset: 0; pointer-events: none; z-index: -1;
  opacity: calc(.04 + var(--mental-progress, 0) * .62);
  background:
    radial-gradient(circle at 50% 18%, rgba(185,255,231,.32), transparent 34%),
    radial-gradient(circle at 20% 82%, rgba(95,231,255,.22), transparent 38%),
    linear-gradient(180deg, rgba(255,255,255,.04), rgba(120,255,210,.1));
  transition: opacity 1.4s ease, filter 1.4s ease;
  filter: saturate(calc(.75 + var(--mental-progress, 0) * .75)) brightness(calc(.65 + var(--mental-progress, 0) * .55));
}
button { font: inherit; border: 0; cursor: pointer; user-select: none; touch-action: manipulation; }
.hidden { display: none !important; }

/* Background */
.bg-stars { position: fixed; inset: 0; pointer-events:none; overflow:hidden; z-index:-1; background:
  radial-gradient(circle at 20% 20%, rgba(90,220,255,.18), transparent 28%),
  radial-gradient(circle at 80% 10%, rgba(160,120,255,.18), transparent 30%),
  radial-gradient(circle at 50% 100%, rgba(80,255,190,.12), transparent 36%); }
.bg-stars::before, .bg-stars::after { content:""; position:absolute; inset:-40%; background-image: radial-gradient(#fff 1px, transparent 1px); background-size: 38px 38px; 
  
  
  opacity:calc(.18 + var(--mental-progress, 0) * .35); 
  
  
  animation: drift 28s linear infinite; 


}



.bg-stars::after { background-size: 71px 71px; opacity:calc(.06 + var(--mental-progress, 0) * .15); animation-duration: 46s; animation-direction: reverse; }
@keyframes drift { to { transform: translate3d(80px,120px,0); } }
body[data-mood="normal"] { background: radial-gradient(circle at top, #202f54 0%, #081124 58%, #030713 100%); }
body[data-mood="anxiety"] { background: radial-gradient(circle at top, #221741 0%, #080b1d 58%, #030713 100%); }
body[data-mood="anger"] { background: radial-gradient(circle at top, #3a1627 0%, #130611 58%, #030713 100%); }
body[data-mood="sadness"] { background: radial-gradient(circle at top, #143150 0%, #061024 58%, #030713 100%); }
body[data-mood="fatigue"] { background: radial-gradient(circle at top, #282f3f 0%, #10131d 58%, #030713 100%); }
body[data-progress="clear"] .board-wrap { filter: brightness(1.06); }
body[data-progress="bright"] .board-wrap, body[data-progress="hope"] .board-wrap { filter: brightness(1.12) saturate(1.08); }
body[data-progress="bright"] #board, body[data-progress="hope"] #board { box-shadow: 0 18px 60px rgba(0,0,0,.36), inset 0 0 34px rgba(185,255,231,.18), 0 0 28px rgba(95,231,255,.16); }

/* PC layout */
.app { height: 100dvh; display: flex; flex-direction: column; gap: 8px; padding: 8px; max-width: 980px; margin: 0 auto; }
.topbar { height: 42px; min-height: 42px; display: flex; align-items: center; gap: 8px; position: relative; z-index:2; }
.topbar div { flex: 1; font-weight: 800; letter-spacing: .08em; }
.topbar div span { color:#b9ffe7; text-shadow:0 0 12px rgba(95,231,255,.4); }
.topbar small { margin-left: 8px; opacity: .65; font-weight: 600; }
.topbar button { height: 34px; padding: 0 12px; border-radius: 10px; background: linear-gradient(#fff, #dceeff); color: #121827; font-weight: 800; }
.game-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 130px auto 130px; gap: 10px; align-items: center; justify-content: center; }
.mobile-game-info { display: none; }
.board-wrap { position: relative; height: min(calc(100dvh - 160px), 620px); aspect-ratio: 1 / 2; display: flex; overflow:hidden; }


#board {
  background: rgba(25,40,80,.75);
}


#fx { position:absolute; inset:0; width:100%; height:100%; pointer-events:none; border-radius:14px; }
.panel { align-self: stretch; display: flex; flex-direction: column; gap: 10px; justify-content: center; min-width: 0; }
.box, .stats { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; padding: 10px; }
h2 { font-size: 13px; margin: 0 0 6px; opacity: .8; letter-spacing: .12em; }
#hold, #next { width: 100%; height: auto; background: rgba(0,0,0,.18); border-radius: 10px; }
.stats p { margin: 8px 0; display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: rgba(255,255,255,.75); }
.stats b { color: #fff; font-size: 16px; }
.effect { min-height: 54px; padding: 10px; border-radius: 14px; background: rgba(255,255,255,.08); font-weight: 900; text-align: center; display:flex; align-items:center; justify-content:center; color:#b9ffe7; }
.message { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: rgba(0,0,0,.55); border-radius: 14px; font-size: 28px; font-weight: 900; letter-spacing: .04em; white-space: pre-line; z-index:15; }

/* Title */
.title-screen { position: fixed; inset: 0; z-index: 10; display:grid; place-items:center; padding:20px; background: rgba(3,7,19,.72); backdrop-filter: blur(10px); }
.title-screen.hidden { display:none; }
.title-card { width:min(520px, 94vw); text-align:center; border:1px solid rgba(170,230,255,.28); border-radius:28px; padding:28px 22px; background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.05)); box-shadow: 0 24px 80px rgba(0,0,0,.5); }
.official { margin:0 0 12px; color:#b9ffe7; font-weight:800; letter-spacing:.08em; }
.title-card h1 { margin:0; font-size: clamp(44px, 11vw, 82px); line-height:.82; letter-spacing:.05em; text-shadow: 0 0 22px rgba(95,231,255,.55); }
.title-card h1 span { display:block; }
.subtitle { margin:18px 0; font-weight:800; color:rgba(255,255,255,.86); }
.mood-select { display:grid; grid-template-columns: repeat(5,1fr); gap:8px; margin:18px 0; }
.mood-select button, .start-btn { border-radius:999px; padding:10px 8px; font-weight:900; background: rgba(255,255,255,.13); color:white; border:1px solid rgba(255,255,255,.2); }
.mood-select button.selected { background: #b9ffe7; color:#071020; }
.start-btn { width: min(260px, 80%); padding:14px; background: linear-gradient(90deg,#5fe7ff,#b9ffe7); color:#071020; font-size:20px; box-shadow:0 8px 0 rgba(0,0,0,.25); }
.howto { margin:16px 0 0; opacity:.72; font-size:13px; line-height:1.6; }

/* Effects */
.toast { position:absolute; top: 42%; left:50%; transform:translate(-50%,-50%); min-width: 180px; text-align:center; padding:14px 18px; border-radius:999px; background:rgba(185,255,231,.92); color:#071020; font-weight:1000; box-shadow:0 0 32px rgba(95,231,255,.45); animation: popToast .9s ease both; pointer-events:none; z-index:20; }
@keyframes popToast { 0%{opacity:0; transform:translate(-50%,-40%) scale(.85)} 20%{opacity:1; transform:translate(-50%,-50%) scale(1.05)} 100%{opacity:0; transform:translate(-50%,-70%) scale(1)} }
.flash { animation: screenFlash .28s ease; }
@keyframes screenFlash { 0%,100%{filter:none} 45%{filter:brightness(1.9) saturate(1.4)} }
.talt { position: fixed; right: 14px; bottom: 14px; z-index:3; display:flex; align-items:flex-end; gap:8px; pointer-events:none; }
.talt-face { width:46px; height:46px; border-radius:50%; display:grid; place-items:center; font-weight:1000; background:linear-gradient(160deg,#5fe7ff,#b9ffe7); color:#071020; box-shadow:0 10px 28px rgba(0,0,0,.35); }
.talt-bubble { max-width:250px; padding:10px 12px; border-radius:15px 15px 4px 15px; background:rgba(255,255,255,.92); color:#071020; font-size:13px; font-weight:800; box-shadow:0 10px 28px rgba(0,0,0,.25); transition:.25s; }
.talt-bubble.pulse { transform: translateY(-4px); }

/* Controls */
.mobile-controls { display: none; }
.control-pad { min-width:0; }
.mobile-controls button { width:100%; height:100%; min-height:0; border-radius:16px; color:#071020; font-weight:1000; letter-spacing:.03em; border:1px solid rgba(255,255,255,.55); background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(220,242,255,.9)); box-shadow:0 5px 0 rgba(5,12,24,.62), 0 10px 20px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.95); }
.mobile-controls button:active { transform: translateY(3px); box-shadow:0 2px 0 rgba(5,12,24,.62), 0 6px 14px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.95); }
.drop-soft { background: linear-gradient(180deg, #e8fbff, #b9ffe7) !important; }
.drop-hard { background: linear-gradient(180deg, #b9ffe7, #5fe7ff) !important; }
.keyboard-help { position: fixed; left: 16px; bottom: 16px; z-index: 4; width: 190px; padding: 12px; border-radius: 16px; background: rgba(8, 14, 30, .86); border: 1px solid rgba(185,255,231,.32); color: #fff; font-size: 12px; line-height: 1.35; box-shadow: 0 14px 36px rgba(0,0,0,.35), 0 0 18px rgba(95,231,255,.12); }
.keyboard-help h3 { margin:0 0 8px; color:#b9ffe7; font-size:13px; }
.keyboard-help p { margin:4px 0; }
.keyboard-help b { color:#5fe7ff; }

/* Tablet */
@media (min-width: 761px) and (max-width: 1100px) {
  .app { max-width:none; width:100vw; height:100dvh; padding:8px 10px calc(8px + env(safe-area-inset-bottom)); gap:8px; }
  .keyboard-help { display:none; }
  .topbar { height:38px; min-height:38px; }
  .game-layout { grid-template-columns:118px minmax(260px, auto) 118px; gap:8px; }
  .board-wrap { height:min(calc(100dvh - 220px), 600px); max-height:600px; }
  .panel { align-self:center; }
  .mobile-controls { display:grid; grid-template-columns:repeat(5, 1fr); grid-template-rows:60px 60px; gap:8px; height:130px; min-height:130px; max-width:760px; width:100%; margin:0 auto; padding:0 6px calc(4px + env(safe-area-inset-bottom)); }
  .control-pad { display:contents; }
  button[data-action="left"] { grid-column:1; grid-row:1; font-size:30px; }
  button[data-action="ccw"] { grid-column:2; grid-row:1; }
  button[data-action="hold"] { grid-column:3; grid-row:1; }
  button[data-action="cw"] { grid-column:4; grid-row:1; }
  button[data-action="right"] { grid-column:5; grid-row:1; font-size:30px; }
  button[data-action="down"] { grid-column:1 / 4; grid-row:2; }
  button[data-action="hard"] { grid-column:4 / 6; grid-row:2; }
}

/* Smartphone */
@media (max-width: 760px) {
  html, body { position:fixed; inset:0; width:100%; height:100%; overflow:hidden; }
  body { min-height:100svh; }
  .app { width:100vw; height:100svh; max-width:none; overflow:hidden; padding:4px 5px calc(4px + env(safe-area-inset-bottom)); gap:4px; }
  .keyboard-help { display:none; }
  .topbar { height:29px; min-height:29px; gap:4px; }
  .topbar div { font-size:10px; letter-spacing:.01em; }
  .topbar small { display:none; }
  .topbar button { height:26px; padding:0 5px; font-size:8px; border-radius:7px; }
  .mobile-game-info { display:none !important; }
  .game-layout { flex:1 1 auto; min-height:0; width:100%; display:grid; grid-template-columns:58px minmax(0, 1fr) 58px; grid-template-areas:"left board right"; grid-template-rows:1fr; gap:5px; align-items:center; justify-content:center; }
  .left-panel { grid-area:left; }
  .right-panel { grid-area:right; }
  .board-wrap { grid-area:board; justify-self:center; align-self:center; width:min(calc((100svh - 170px) / 2), calc(100vw - 126px)); height:min(calc(100svh - 170px), calc((100vw - 126px) * 2)); min-width:168px; min-height:336px; max-width:300px; max-height:600px; aspect-ratio:1/2; }
  #board { border-width:2px; border-radius:10px; }
  #fx { border-radius:10px; }
  .left-panel, .right-panel { width:58px; height:100%; display:flex; flex-direction:column; justify-content:center; gap:6px; overflow:visible; }
  .box, .stats { padding:4px; border-radius:10px; }
  .left-panel .box, .right-panel .box { width:58px; min-height:92px; display:flex; flex-direction:column; align-items:center; justify-content:center; }
  .left-panel .box h2, .right-panel .box h2 { font-size:0; margin:0 0 3px; line-height:1; text-align:center; }
  .left-panel .box h2::after { content:"HOLD"; font-size:9px; color:rgba(255,255,255,.85); letter-spacing:.05em; }
  .right-panel .box h2::after { content:"NEXT"; font-size:9px; color:rgba(255,255,255,.85); letter-spacing:.05em; }
  #hold { width:50px; height:50px; max-height:none; }
  #next { width:50px; height:140px; object-fit:contain; }
  .stats { width:58px; height:auto; padding:5px 3px; display:block; }
  .stats p { margin:4px 0; font-size:8px; line-height:1.05; text-align:center; display:block; }
  .stats b { display:block; font-size:11px; line-height:1.05; }
  .effect { width:58px; min-height:48px; padding:4px; font-size:8px; line-height:1.1; border-radius:10px; }
  .mobile-controls { display:grid; grid-template-columns:repeat(5, 1fr); grid-template-rows:58px 58px; gap:7px; height:124px; min-height:124px; padding:0 6px calc(4px + env(safe-area-inset-bottom)); }
  .control-pad { display:contents; }
  .mobile-controls button { border-radius:14px; font-size:12px; line-height:1.1; padding:0 4px; }
  button[data-action="left"] { grid-column:1; grid-row:1; font-size:24px; }
  button[data-action="ccw"] { grid-column:2; grid-row:1; }
  button[data-action="hold"] { grid-column:3; grid-row:1; }
  button[data-action="cw"] { grid-column:4; grid-row:1; }
  button[data-action="right"] { grid-column:5; grid-row:1; font-size:24px; }
  button[data-action="down"] { grid-column:1 / 4; grid-row:2; }
  button[data-action="hard"] { grid-column:4 / 6; grid-row:2; }
  .message { font-size:18px; border-radius:10px; }
  .toast { min-width:140px; font-size:14px; padding:10px 12px; }
  .talt { right:8px; bottom:calc(132px + env(safe-area-inset-bottom)); }
  .talt-bubble { display:none; }
  .talt-face { width:34px; height:34px; font-size:12px; }
  .title-card { padding:22px 14px; border-radius:22px; }
  .mood-select { grid-template-columns:repeat(3,1fr); gap:7px; }
  .mood-select button { font-size:12px; padding:9px 4px; }
}

/* iPhone SE */
@media (max-width: 390px), (max-height: 700px) {
  .app { padding-top:4px; gap:4px; }
  .topbar { height:27px; min-height:27px; }
  .topbar button { height:25px; font-size:8px; padding:0 4px; }
  .game-layout { grid-template-columns:52px minmax(0,1fr) 52px; gap:4px; }
  .left-panel, .right-panel, .stats, .effect, .left-panel .box, .right-panel .box { width:52px; }
  .board-wrap { width:min(calc((100svh - 158px) / 2), calc(100vw - 112px)); height:min(calc(100svh - 158px), calc((100vw - 112px) * 2)); min-width:150px; min-height:300px; }
  #hold { width:44px; height:44px; }
  #next { width:44px; height:120px; }
  .stats p { font-size:7.5px; margin:3px 0; }
  .stats b { font-size:10px; }
  .effect { min-height:42px; font-size:7.5px; }
  .mobile-controls { grid-template-rows:52px 52px; height:112px; min-height:112px; gap:6px; }
  .mobile-controls button { border-radius:12px; font-size:11px; }
  button[data-action="left"], button[data-action="right"] { font-size:22px; }
}

/* Landscape */
@media (orientation: landscape) and (max-height: 540px) and (max-width: 1100px) {
  .app { flex-direction:row; gap:6px; }
  .topbar { width:86px; height:auto; min-height:0; flex-direction:column; align-items:stretch; }
  .topbar div { font-size:12px; }
  .game-layout { flex:1; }
  .board-wrap { width:min(calc((100svh - 12px) / 2), calc(100vw - 380px)); height:min(calc(100svh - 12px), calc((100vw - 380px) * 2)); }
  .mobile-controls { width:250px; height:auto; min-height:0; }
}

.talt-character {
  width: 72px;
  height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,.35));
  transition: transform .25s ease, filter .25s ease;
}

.talt-character.happy {
  transform: translateY(-8px) scale(1.08);
  filter: drop-shadow(0 0 18px rgba(185,255,231,.75));
}

.achievement-toast,
.gacha-toast {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(8,14,30,.96);
  border: 1px solid rgba(185,255,231,.5);
  color: #fff;
  font-weight: 900;
  text-align: center;
  box-shadow: 0 18px 48px rgba(0,0,0,.45), 0 0 26px rgba(95,231,255,.25);
}

.emotion-float {
  position: absolute;
  pointer-events: none;
  z-index: 30;
  font-weight: 900;
  color: #b9ffe7;
  text-shadow: 0 0 12px rgba(95,231,255,.8);
  animation: emotionFloat 1.2s ease forwards;
}

@keyframes emotionFloat {
  0% { opacity: 0; transform: translateY(20px) scale(.8); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-70px) scale(1.15); }
}


@media (max-width: 760px) {
  .talt-character {
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 390px), (max-height: 700px) {
  .talt-character {
    width: 40px;
    height: 40px;
  }
}

.sp-flick-guide {
  display: none;
}

@media (max-width: 760px) {
  .sp-flick-guide {
    grid-column: 1 / 4;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 3px;
    padding: 4px;
    border-radius: 10px;
    background: rgba(8,14,30,.78);
    border: 1px solid rgba(185,255,231,.25);
    font-size: 10px;
    font-weight: 800;
    color: rgba(255,255,255,.9);
    text-align: center;
  }

  .sp-flick-guide span {
    padding: 4px 2px;
    border-radius: 7px;
    background: rgba(255,255,255,.08);
    white-space: nowrap;
  }

  .game-layout {
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "guide guide guide"
      "left board right";
  }
}

@media (max-width: 390px), (max-height: 700px) {
  .sp-flick-guide {
    font-size: 9px;
    gap: 3px;
    padding: 3px;
  }

  .sp-flick-guide span {
    padding: 3px 1px;
  }
}

.gacha-toast{
  position:fixed;
  inset:0;
  z-index:99999;

  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;

  background:rgba(0,0,0,.85);
  backdrop-filter:blur(8px);
}

.gacha-title{
  font-size:28px;
  font-weight:900;
  color:#ffe45f;
  margin-bottom:12px;
}

.gacha-result-img{
  width:280px;
  max-width:70vw;
  height:auto;

  animation:gachaPop .4s ease;
}

.gacha-name{
  margin-top:12px;
  font-size:22px;
  font-weight:900;
  color:white;
}

@keyframes gachaPop{
  from{
    transform:scale(.4);
    opacity:0;
  }
  to{
    transform:scale(1);
    opacity:1;
  }
}

/* ガチャ演出：中央表示 */
.gacha-toast {
  position: fixed !important;
  inset: 0 !important;
  left: 0 !important;
  top: 0 !important;
  transform: none !important;
  z-index: 99999 !important;

  display: flex !important;
  align-items: center !important;
  justify-content: center !important;

  padding: 20px !important;
  background:
    radial-gradient(circle at center, rgba(95,231,255,.22), transparent 42%),
    rgba(0,0,0,.82) !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.gacha-card {
  width: min(86vw, 360px);
  min-height: 420px;
  padding: 22px 18px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(255,255,255,.16), rgba(8,14,30,.96));
  border: 1px solid rgba(185,255,231,.45);
  box-shadow:
    0 22px 70px rgba(0,0,0,.55),
    0 0 34px rgba(95,231,255,.28);

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: gachaCardPop .42s ease both;
}

.gacha-title {
  font-size: 24px;
  font-weight: 1000;
  color: #ffe45f;
  text-shadow: 0 0 18px rgba(255,228,95,.45);
  margin-bottom: 12px;
}

.gacha-result-img {
  width: min(68vw, 260px);
  height: min(68vw, 260px);
  object-fit: contain;
  display: block;
  margin: 4px auto 12px;
  filter: drop-shadow(0 18px 28px rgba(0,0,0,.45));
  animation: gachaImgPop .55s cubic-bezier(.2,1.4,.35,1) both;
}

.gacha-name {
  font-size: 20px;
  font-weight: 1000;
  color: #fff;
  text-align: center;
  margin-bottom: 14px;
}

.gacha-close {
  padding: 10px 22px;
  border-radius: 999px;
  font-weight: 900;
  background: linear-gradient(90deg,#5fe7ff,#b9ffe7);
  color: #071020;
}

@keyframes gachaCardPop {
  from {
    opacity: 0;
    transform: scale(.82) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes gachaImgPop {
  from {
    opacity: 0;
    transform: scale(.4) rotate(-8deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@media (max-width: 760px) {
  .gacha-card {
    width: 88vw;
    min-height: 360px;
    padding: 18px 14px;
  }

  .gacha-title {
    font-size: 20px;
  }

  .gacha-result-img {
    width: min(72vw, 220px);
    height: min(72vw, 220px);
  }

  .gacha-name {
    font-size: 17px;
  }
}

.gacha-note {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 800;
  color: #b9ffe7;
  text-align: center;
}
/* =========================================================
   SP height fix - keep entire game inside viewport
   Add this at the END of style.css
========================================================= */
@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    height: 100svh;
    min-height: 100svh;
    overflow: hidden;
  }

  .app {
    width: 100vw;
    height: 100svh;
    max-height: 100svh;
    overflow: hidden;
    display: grid;
    grid-template-rows: 28px auto minmax(0, 1fr) 108px;
    gap: 4px;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  }

  .topbar {
    grid-row: 1;
    height: 28px;
    min-height: 28px;
  }

  .sp-flick-guide {
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin: 0;
    padding: 3px;
    font-size: 10px;
    line-height: 1.1;
  }

  .sp-flick-guide span {
    padding: 4px 2px;
  }

  .game-layout {
    grid-row: 3;
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-columns: 58px minmax(0, auto) 58px;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "left board right";
    gap: 5px;
    align-items: center;
    justify-content: center;
  }

  .board-wrap {
    grid-area: board;
    width: auto;
    height: 100%;
    max-height: 100%;
    max-width: calc((100svh - 154px) / 2);
    aspect-ratio: 1 / 2;
    min-width: 0;
    min-height: 0;
    justify-self: center;
    align-self: center;
  }

  #board,
  #fx {
    width: 100%;
    height: 100%;
  }

  .left-panel,
  .right-panel {
    height: 100%;
    width: 58px;
    justify-content: center;
    gap: 5px;
  }

  .left-panel .box,
  .right-panel .box,
  .stats,
  .effect {
    width: 58px;
  }

  #hold {
    width: 50px;
    height: 50px;
  }

  #next {
    width: 50px;
    height: 132px;
  }

  .mobile-controls {
    grid-row: 4;
    height: 104px;
    min-height: 104px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: 48px 48px;
    gap: 6px;
    padding: 0;
  }

  .mobile-controls button {
    border-radius: 12px;
    font-size: 11px;
  }

  button[data-action="left"],
  button[data-action="right"] {
    font-size: 22px;
  }

  .talt {
    right: 7px;
    bottom: calc(112px + env(safe-area-inset-bottom));
    z-index: 20;
  }

  .talt-character {
    width: 38px;
    height: 38px;
  }
}

@media (max-width: 390px), (max-height: 700px) {
  .app {
    grid-template-rows: 26px auto minmax(0, 1fr) 100px;
    padding: 3px 5px calc(3px + env(safe-area-inset-bottom));
    gap: 3px;
  }

  .topbar {
    height: 26px;
    min-height: 26px;
  }

  .topbar button {
    height: 24px;
    font-size: 7.5px;
    padding: 0 4px;
  }

  .sp-flick-guide {
    font-size: 9px;
    gap: 3px;
    padding: 3px;
  }

  .game-layout {
    grid-template-columns: 50px minmax(0, auto) 50px;
    gap: 4px;
  }

  .board-wrap {
    max-width: calc((100svh - 142px) / 2);
  }

  .left-panel,
  .right-panel,
  .left-panel .box,
  .right-panel .box,
  .stats,
  .effect {
    width: 50px;
  }

  #hold {
    width: 43px;
    height: 43px;
  }

  #next {
    width: 43px;
    height: 112px;
  }

  .stats p {
    font-size: 7px;
    margin: 3px 0;
  }

  .stats b {
    font-size: 9.5px;
  }

  .effect {
    min-height: 38px;
    font-size: 7px;
  }

  .mobile-controls {
    height: 96px;
    min-height: 96px;
    grid-template-rows: 45px 45px;
    gap: 5px;
  }

  .mobile-controls button {
    font-size: 10px;
    border-radius: 11px;
  }

  .talt {
    bottom: calc(104px + env(safe-area-inset-bottom));
  }

  .talt-character {
    width: 34px;
    height: 34px;
  }
}


/* SP・タブレット時：タルト君を操作ボタンにかぶせない */
@media (max-width: 1100px) {
  .talt {
    right: 10px;
    bottom: calc(140px + env(safe-area-inset-bottom));
    z-index: 6;
  }

  .talt-bubble {
    display: none;
  }

  .talt-character {
    width: 46px;
    height: 46px;
  }
}

/* iPhone SEなど小さい画面 */
@media (max-width: 390px), (max-height: 700px) {
  .talt {
    right: 8px;
    bottom: calc(118px + env(safe-area-inset-bottom));
  }

  .talt-character {
    width: 38px;
    height: 38px;
  }
}