:root{
  --ink:#172038;
  --muted:#68758a;
  --paper:#fffdf8;
  --line:#dfe4ea;
  --blue:#218ee6;
  --blue-dark:#0760b8;
  --yellow:#ffd44d;
  --orange:#f08a24;
  --shadow:0 14px 34px rgba(31,43,62,.15);
  --tile:clamp(38px,10vw,62px);
}
*{box-sizing:border-box}
html{scroll-behavior:auto}
body{margin:0;font-family:system-ui,-apple-system,"Hiragino Kaku Gothic ProN","Yu Gothic",sans-serif;background:#edf1f5;color:var(--ink)}
button,input{font:inherit}
button{cursor:pointer}
button:focus-visible,input:focus-visible,a:focus-visible{outline:4px solid #ffbd26;outline-offset:2px}
img{max-width:100%;display:block}
.tower-app{width:min(720px,100%);margin:0 auto;min-height:100vh;padding:14px 14px 48px;background:linear-gradient(rgba(249,251,255,.93),rgba(255,250,240,.97)),url("../../kyokasho_tower_background.png") center/cover fixed}
.top-nav{display:flex;justify-content:space-between;gap:8px;margin-bottom:10px}
.nav-pill{border:1px solid #d8dee7;background:rgba(255,255,255,.94);color:var(--ink);border-radius:999px;padding:9px 13px;font-size:13px;font-weight:900;box-shadow:0 4px 14px rgba(30,42,60,.07)}
.screen-heading{text-align:center;margin:18px 0 16px}.screen-heading h1{font-size:clamp(28px,7vw,38px);margin:0 0 7px}.screen-heading p{margin:0;color:var(--muted);font-weight:800;line-height:1.55}
.title-card{position:relative;overflow:hidden;min-height:calc(100vh - 76px);border-radius:28px;padding:26px 18px;display:grid;align-content:center;text-align:center;background:linear-gradient(to bottom,rgba(11,23,43,.03) 12%,rgba(11,23,43,.13) 52%,rgba(11,23,43,.48) 100%),url("../../kyokasho_tower_background.png") center 47%/cover no-repeat;color:#fff;box-shadow:var(--shadow)}
.title-card>*{position:relative;z-index:1}
.title-logo{width:min(620px,98%);max-height:280px;object-fit:contain;margin:0 auto 12px;filter:drop-shadow(0 10px 18px rgba(16,30,58,.3))}
/* Only the title screen logo moves upward; in-game round logos stay unchanged. */
.title-card > .title-logo{transform:translateY(clamp(-86px,-10dvh,-52px))}
.title-copy{margin:8px auto 20px;padding:10px 15px;border-radius:17px;background:rgba(30,38,58,.46);font-weight:900;line-height:1.7;max-width:520px;text-shadow:0 2px 7px rgba(0,0,0,.5);backdrop-filter:blur(3px)}
.card{background:rgba(255,253,249,.97);border:1px solid rgba(219,215,207,.95);border-radius:23px;padding:17px;box-shadow:var(--shadow);margin-bottom:13px}
.stack{display:grid;gap:12px}
.grid2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px}
.grid3{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:9px}
.btn{border:0;border-radius:16px;padding:13px 15px;min-height:52px;background:linear-gradient(#45abff,#1881dc);color:#fff;font-weight:950;box-shadow:0 5px 0 #0861b5;touch-action:manipulation}.btn:active{transform:translateY(3px);box-shadow:0 2px 0 #0861b5}.btn.secondary{background:#edf2f7;color:var(--ink);box-shadow:0 4px 0 #c8d1dc}.btn.yellow{background:linear-gradient(#ffe373,#ffc832);color:#352c15;box-shadow:0 5px 0 #c98a13}.btn.danger{background:linear-gradient(#ff737d,#e24151);box-shadow:0 5px 0 #a32232}.btn.full{width:100%}.btn:disabled{opacity:.35;cursor:not-allowed;transform:none;box-shadow:none}
.section-row{display:flex;justify-content:space-between;gap:12px;align-items:center}.section-row h2{margin:0 0 5px;font-size:23px}.section-row p{margin:0;color:var(--muted);font-weight:800}.small-btn{border:2px solid #d9e1e9;background:#fff;color:#56647a;border-radius:14px;padding:10px 14px;font-weight:900}
.member-chips{display:flex;gap:8px;flex-wrap:wrap;margin-top:13px}.member-chip{padding:8px 11px;border-radius:999px;background:#fff;border:1px solid #dce3eb;font-weight:900}
.setup-note{margin:0;color:#68758a;font-weight:800;line-height:1.6}.round-badge{display:inline-flex;align-items:center;justify-content:center;margin-top:8px;padding:7px 11px;border-radius:999px;background:#fff2d8;color:#905d14;font-size:13px;font-weight:950}
.player-card{display:grid;gap:10px}.player-line{display:grid;grid-template-columns:54px minmax(0,1fr);gap:10px;align-items:center}.avatar{width:48px;height:48px;border-radius:50%;display:grid;place-items:center;background:linear-gradient(145deg,#e9f6ff,#fff0db);font-size:25px;border:2px solid #fff;box-shadow:0 3px 10px rgba(30,52,85,.12)}.avatar.large{width:84px;height:84px;font-size:44px;margin:0 auto 9px}.player-line input{width:100%;min-width:0;padding:13px;border:2px solid #d9e1e9;border-radius:13px;background:#fff;color:var(--ink);font-size:16px}.icon-pick{display:grid;grid-template-columns:repeat(6,1fr);gap:6px}.icon-btn{min-height:44px;border:1px solid #dce2ea;background:#fff;border-radius:12px;font-size:22px}.icon-btn.selected{outline:3px solid #2a91e3;background:#eaf6ff}.icon-btn:disabled{opacity:.2}
.book-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.book-info{display:grid;grid-template-columns:72px minmax(0,1fr);gap:10px;align-items:center;padding:12px;border:1px solid #e0e5eb;border-radius:17px;background:#fff}.book-info img{width:72px;height:72px;object-fit:contain}.book-info strong{display:block;font-size:19px}.book-info span{display:block;margin-top:3px;color:var(--muted);font-size:12px;font-weight:800}
.rule-progress{text-align:center;color:#7a8595;font-weight:900;margin-bottom:10px}.rule-visual{display:grid;place-items:center;min-height:190px;border-radius:20px;background:linear-gradient(145deg,#f8fbff,#fff7e8);padding:16px;margin-bottom:13px}.rule-visual img{width:105px;height:105px;object-fit:contain}.rule-visual .mini-books{display:flex;align-items:end;justify-content:center;gap:3px}.rule-visual .mini-books img{width:48px;height:48px}.rule-card h2{margin:0 0 8px;text-align:center}.rule-card p{margin:0;color:#526075;font-weight:800;line-height:1.75;text-align:center}
.round-hero{text-align:center}.round-hero img{width:min(420px,78%);max-height:180px;object-fit:contain;margin:0 auto 8px}.start-player{display:grid;justify-items:center;gap:7px;margin:16px 0}.start-player strong{font-size:23px}.score-strip{display:flex;gap:7px;overflow:auto;padding:3px 0 7px;scrollbar-width:none}.score-strip::-webkit-scrollbar{display:none}.score-chip{flex:0 0 auto;padding:8px 10px;border-radius:999px;background:#fff;border:1px solid #dfe5eb;font-size:12px;font-weight:900}
.privacy-card{min-height:420px;border-radius:24px;padding:26px 18px;background:linear-gradient(160deg,#1d2a43,#0c1321);color:#fff;box-shadow:var(--shadow);display:grid;place-items:center;align-content:center;text-align:center;gap:12px}.privacy-card h2{margin:0;font-size:26px;line-height:1.45}.privacy-card p{margin:0;color:#cbd4e0;font-weight:800}.hold-btn{width:min(360px,100%);position:relative;overflow:hidden;user-select:none;-webkit-user-select:none;touch-action:none}.hold-btn span{position:relative;z-index:2}.hold-btn i{position:absolute;inset:0 auto 0 0;width:0;background:rgba(255,255,255,.34);z-index:1}.hold-btn.holding i{width:100%;transition:width .55s linear}
.hand-private{background:linear-gradient(160deg,#17263e,#0b1321);color:#fff}.hand-private .private-head{text-align:center;margin-bottom:12px}.hand-private .private-head h2{margin:6px 0 4px}.hand-private .private-head p{margin:0;color:#c9d3e0;font-weight:750}.hand-grid{display:grid;gap:9px}.hand-book{display:grid;grid-template-columns:68px minmax(0,1fr) auto;gap:10px;align-items:center;border:2px solid rgba(255,255,255,.18);border-radius:17px;background:rgba(255,255,255,.09);color:#fff;padding:9px 11px;text-align:left;touch-action:manipulation}.hand-book img{width:66px;height:66px;object-fit:contain}.hand-book strong{display:block;font-size:19px}.hand-book span{display:block;color:#d7deea;font-size:12px;font-weight:800;margin-top:2px}.hand-book b{font-size:22px}.hand-book:disabled{opacity:.36}.hand-book.playable{border-color:#66c4ff;background:rgba(53,152,225,.18)}
.board-card{padding:14px 8px 16px;overflow:hidden}.board-meta{display:flex;justify-content:space-between;gap:8px;align-items:center;padding:0 8px 9px;color:#667286;font-size:12px;font-weight:900}.tower-board{display:grid;justify-items:center;gap:2px;min-height:120px;padding:8px 0 5px}.tower-row{display:flex;justify-content:center;gap:0}.tower-cell{width:var(--tile);height:var(--tile);display:grid;place-items:center}.tower-book{width:calc(var(--tile) - 2px);height:calc(var(--tile) - 2px);object-fit:contain;filter:drop-shadow(0 2px 2px rgba(25,32,45,.14))}.tower-slot{width:calc(var(--tile) - 7px);height:calc(var(--tile) - 7px);border:2px dashed #55aeea;border-radius:11px;background:#eaf7ff;color:#1478c8;font-weight:1000;font-size:22px;display:grid;place-items:center;padding:0;box-shadow:none}.tower-empty{width:calc(var(--tile) - 2px);height:calc(var(--tile) - 2px)}.board-empty{padding:30px 12px;color:#748095;font-weight:900;text-align:center}.base-actions{display:grid;grid-template-columns:1fr 1fr;gap:9px;margin-top:12px}.base-actions.one{grid-template-columns:1fr}.subject-selected{display:flex;align-items:center;justify-content:center;gap:10px;margin:0 0 12px}.subject-selected img{width:64px;height:64px;object-fit:contain}.subject-selected strong{font-size:22px}.subject-selected span{display:block;color:#6b7688;font-weight:800;font-size:12px}
.no-move-card{text-align:center}.no-move-card img{width:110px;height:110px;object-fit:contain;margin:0 auto 8px;filter:grayscale(.15)}.no-move-card h2{margin:5px 0}.penalty-big{font-size:37px;font-weight:1000;color:#e14b42;margin:10px 0}
.turn-event{text-align:center}.turn-event .event-icon{font-size:48px}.turn-event h2{margin:5px 0 7px;font-size:27px}.turn-event p{margin:0;color:#667286;font-weight:800;line-height:1.6}.next-player{margin:14px 0;padding:12px;border-radius:16px;background:#f2f7fb;text-align:center;font-weight:900}
.result-table{display:grid;gap:8px}.result-row{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:8px;align-items:center;padding:11px;border:1px solid #e0e5eb;border-radius:14px;background:#fff}.result-row .who{font-weight:900}.result-row .change{font-size:13px;font-weight:900;color:#6b7687}.result-row .total{font-size:19px;font-weight:1000}.change.plus{color:#d44942}.change.minus{color:#26925d}
.ranking{display:grid;gap:8px}.rank-row{display:grid;grid-template-columns:46px minmax(0,1fr) auto;gap:9px;align-items:center;padding:13px;border:1px solid #e0e5eb;border-radius:15px;background:#fff}.rank-row b{font-size:20px;color:#1684df}.rank-row span{font-weight:900}.rank-row strong{font-size:21px}.winner-card{text-align:center;background:linear-gradient(145deg,#fff9df,#fff);border:2px solid #f0c648}.winner-card .winner-crown{font-size:48px}.winner-card h2{margin:4px 0 7px;font-size:29px}
.modal-backdrop{position:fixed;inset:0;z-index:999;background:rgba(9,18,31,.68);padding:18px;display:grid;place-items:center}.modal{width:min(480px,100%);background:#fff;border-radius:24px;padding:20px;box-shadow:0 24px 70px rgba(0,0,0,.35);text-align:center}.modal h2{margin:0 0 8px}.modal p{margin:0 0 15px;color:#657185;font-weight:800;line-height:1.6}.modal-actions{display:grid;grid-template-columns:1fr 1fr;gap:9px}
@media(max-width:520px){
  .tower-app{padding:12px 12px 42px}.title-card{border-radius:24px;padding:22px 14px}.title-logo{max-height:220px}
  .book-grid{grid-template-columns:1fr}.book-info{grid-template-columns:64px minmax(0,1fr)}.book-info img{width:64px;height:64px}
  .icon-pick{grid-template-columns:repeat(5,1fr)}
  .result-row{grid-template-columns:minmax(0,1fr) auto}.result-row .total{grid-column:2;grid-row:1 / span 2}.result-row .change{grid-column:1}
}

/* Kyokasho Tower mobile-flow refinements */
.board-summary{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:2px 12px;align-items:center;margin:0 0 12px;padding:12px 14px;border:1px solid #dfe5eb;border-radius:17px;background:rgba(255,255,255,.94);box-shadow:0 7px 18px rgba(31,43,62,.08)}
.board-summary span{font-size:12px;color:#6d788b;font-weight:900}
.board-summary strong{grid-row:1 / span 2;grid-column:2;font-size:24px}
.board-summary em{font-style:normal;font-size:13px;color:#58667a;font-weight:900}
.screen-pass .privacy-card{min-height:330px}
.screen-hand{--tile:clamp(28px,7.5vw,43px)}
.screen-hand .board-card{padding:10px 6px 12px;margin-bottom:10px}
.screen-hand .board-meta{padding-bottom:5px}
.screen-hand .tower-board{min-height:80px;padding:4px 0}
.screen-hand .hand-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.screen-hand .hand-book{min-height:142px;display:grid;grid-template-columns:1fr auto;grid-template-areas:"img count" "name name" "status status";justify-items:center;align-content:center;gap:2px 6px;padding:9px;text-align:center}
.screen-hand .hand-book img{grid-area:img;width:72px;height:72px}
.screen-hand .hand-book strong{grid-area:name;font-size:18px}
.screen-hand .hand-book b{grid-area:count;align-self:start;font-size:21px}
.screen-hand .hand-book span{grid-area:status;margin:1px 0 0;font-size:11px}
@media(max-width:350px){
  .screen-hand .hand-grid{grid-template-columns:1fr}
  .screen-hand .hand-book{min-height:105px;grid-template-columns:62px minmax(0,1fr) auto;grid-template-areas:"img name count" "img status count";justify-items:start;text-align:left}
  .screen-hand .hand-book img{width:58px;height:58px}
  .screen-hand .hand-book b{align-self:center}
}

/* Five-subject single-row layout: keep all textbooks visible at once */
.book-grid,
.screen-hand .hand-grid{
  display:grid;
  grid-template-columns:repeat(5,minmax(0,1fr));
  gap:5px;
  width:100%;
}

.book-info{
  min-width:0;
  display:grid;
  grid-template-columns:1fr;
  justify-items:center;
  align-content:start;
  gap:3px;
  padding:7px 3px 8px;
  border-radius:13px;
  text-align:center;
}
.book-info img{
  width:clamp(42px,11vw,64px);
  height:clamp(42px,11vw,64px);
  object-fit:contain;
}
.book-info strong{
  display:block;
  font-size:clamp(12px,3.5vw,16px);
  line-height:1.2;
  white-space:nowrap;
}
.book-info span{
  display:block;
  margin-top:1px;
  font-size:clamp(10px,2.8vw,12px);
  white-space:nowrap;
}

.screen-hand .hand-private{
  padding-left:9px;
  padding-right:9px;
}
.screen-hand .hand-grid{
  gap:4px;
}
.screen-hand .hand-book{
  min-width:0;
  min-height:154px;
  display:grid;
  grid-template-columns:1fr;
  grid-template-areas:
    "img"
    "name"
    "count"
    "status";
  justify-items:center;
  align-content:center;
  gap:2px;
  padding:7px 2px;
  border-radius:13px;
  text-align:center;
}
.screen-hand .hand-book img{
  grid-area:img;
  width:clamp(42px,11vw,60px);
  height:clamp(42px,11vw,60px);
  object-fit:contain;
}
.screen-hand .hand-book strong{
  grid-area:name;
  font-size:clamp(12px,3.4vw,16px);
  line-height:1.15;
  white-space:nowrap;
}
.screen-hand .hand-book b{
  grid-area:count;
  align-self:auto;
  font-size:clamp(16px,4.5vw,20px);
  line-height:1.1;
}
.screen-hand .hand-book span{
  grid-area:status;
  margin:1px 0 0;
  font-size:clamp(9px,2.5vw,11px);
  line-height:1.15;
  white-space:nowrap;
}
.rule-visual .mini-books{
  width:100%;
  display:grid;
  grid-template-columns:repeat(5,minmax(0,1fr));
  align-items:end;
  justify-items:center;
  gap:4px;
}
.rule-visual .mini-books img{
  width:min(100%,52px);
  height:auto;
  aspect-ratio:1/1;
  object-fit:contain;
}

@media(max-width:520px){
  .book-grid{grid-template-columns:repeat(5,minmax(0,1fr));gap:4px}
  .book-info{grid-template-columns:1fr;padding:6px 2px 7px}
  .book-info img{width:46px;height:46px}
  .screen-hand .hand-grid{grid-template-columns:repeat(5,minmax(0,1fr));gap:4px}
}
@media(max-width:350px){
  .book-grid,
  .screen-hand .hand-grid{grid-template-columns:repeat(5,minmax(0,1fr));gap:2px}
  .book-info{padding:5px 1px}
  .book-info img{width:38px;height:38px}
  .book-info strong{font-size:11px}
  .book-info span{font-size:9px}
  .screen-hand .hand-book{
    min-height:132px;
    grid-template-columns:1fr;
    grid-template-areas:"img" "name" "count" "status";
    justify-items:center;
    text-align:center;
    padding:5px 1px;
  }
  .screen-hand .hand-book img{width:38px;height:38px}
  .screen-hand .hand-book strong{font-size:11px}
  .screen-hand .hand-book b{font-size:15px}
  .screen-hand .hand-book span{font-size:8px}
}

/* Placement confirmation: board preview on top, compact confirmation below */
.place-confirm{
  padding:10px;
  align-items:center;
}
.place-confirm-modal{
  width:min(640px,100%);
  max-height:94dvh;
  padding:0;
  overflow:hidden;
  display:grid;
  grid-template-rows:minmax(0,1fr) auto;
  text-align:left;
}
.place-preview-pane{
  min-height:0;
  overflow:auto;
  padding:14px 10px 10px;
  background:linear-gradient(180deg,#eef7ff 0%,#fffaf0 100%);
}
.place-preview-board{
  --tile:clamp(34px,9.2vw,60px);
  min-height:240px;
  display:grid;
  align-content:center;
}
.place-preview-meta{
  display:flex;
  justify-content:space-between;
  gap:10px;
  align-items:center;
  padding:2px 8px 10px;
}
.place-preview-meta strong{
  font-size:16px;
}
.place-preview-meta span{
  color:#617086;
  font-size:11px;
  font-weight:900;
  text-align:right;
}
.place-preview-board .tower-board{
  min-height:170px;
  padding:4px 0 8px;
}
.place-preview-board .tower-cell{
  position:relative;
}
.place-preview-board .preview-target{
  z-index:2;
}
.place-preview-board .preview-target::before{
  content:"";
  position:absolute;
  inset:-4px;
  border:3px solid #ff9f1a;
  border-radius:13px;
  background:rgba(255,222,110,.30);
  box-shadow:0 0 0 4px rgba(255,255,255,.85),0 0 20px rgba(255,143,0,.55);
  animation:placeTargetPulse 1s ease-in-out infinite alternate;
}
.place-preview-board .preview-target .tower-book{
  position:relative;
  z-index:2;
}
.preview-here{
  position:absolute;
  z-index:3;
  top:-18px;
  left:50%;
  transform:translateX(-50%);
  padding:3px 7px;
  border-radius:999px;
  background:#ff9218;
  color:#fff;
  font-size:10px;
  font-weight:1000;
  line-height:1;
  white-space:nowrap;
  box-shadow:0 2px 6px rgba(0,0,0,.18);
}
@keyframes placeTargetPulse{
  from{transform:scale(.96);opacity:.8}
  to{transform:scale(1.03);opacity:1}
}
.place-confirm-sheet{
  background:#fff;
  padding:12px 14px 14px;
  border-top:1px solid #e1e6ec;
  box-shadow:0 -8px 22px rgba(25,36,52,.08);
}
.place-confirm-title{
  display:grid;
  grid-template-columns:58px minmax(0,1fr);
  gap:10px;
  align-items:center;
  margin-bottom:10px;
}
.place-confirm-title img{
  width:56px;
  height:56px;
  object-fit:contain;
}
.place-confirm-title h2{
  margin:0 0 3px;
  font-size:21px;
  line-height:1.25;
}
.place-confirm-title p{
  margin:0;
  color:#657185;
  font-size:12px;
  font-weight:800;
  line-height:1.45;
}
.place-confirm-sheet .modal-actions{
  gap:8px;
}
.place-confirm-sheet .btn{
  min-height:48px;
  padding:11px 10px;
}

@media(max-width:520px){
  .place-confirm-modal{max-height:92dvh;border-radius:22px}
  .place-preview-pane{padding:11px 6px 6px}
  .place-preview-board{--tile:clamp(31px,9vw,44px);min-height:205px}
  .place-preview-board .tower-board{min-height:145px}
  .place-preview-meta{padding:2px 6px 8px}
  .place-preview-meta strong{font-size:14px}
  .place-preview-meta span{font-size:10px}
  .place-confirm-sheet{padding:10px 12px 12px}
  .place-confirm-title{grid-template-columns:48px minmax(0,1fr);gap:8px;margin-bottom:8px}
  .place-confirm-title img{width:46px;height:46px}
  .place-confirm-title h2{font-size:19px}
  .place-confirm-title p{font-size:11px}
}

/* Board placement: all legal positions are tapped directly on the pyramid */
.tower-frame{
  width:calc(var(--tile) - 7px);
  height:calc(var(--tile) - 7px);
  border:2px solid #d7e0e9;
  border-radius:9px;
  background:rgba(255,255,255,.42);
  display:block;
}
.tower-slot{
  width:calc(var(--tile) - 7px);
  height:calc(var(--tile) - 7px);
  border:2px dashed #55aeea;
  border-radius:9px;
  background:#eaf7ff;
  color:#1478c8;
  font-weight:1000;
  font-size:22px;
  display:grid;
  place-items:center;
  padding:0;
  box-shadow:none;
  animation:none;
}
.tower-slot::after{content:none}
.tower-slot span{
  display:block;
  line-height:1;
  transform:translateY(-3px);
}
.first-placement{
  min-height:150px;
  align-content:end;
  padding-bottom:12px;
}
.first-slot{
  width:calc(var(--tile) - 7px);
  height:calc(var(--tile) - 7px);
  font-size:24px;
}
.screen-board{
  --tile:clamp(28px,8.9vw,43px);
}
.screen-board .screen-heading{
  margin:10px 0 9px;
}
.screen-board .screen-heading h1{
  font-size:clamp(24px,6.5vw,34px);
  margin-bottom:3px;
}
.screen-board .screen-heading p{
  font-size:12px;
}
.screen-board .subject-selected{
  margin:0 0 7px;
  gap:7px;
}
.screen-board .subject-selected img{
  width:46px;
  height:46px;
}
.screen-board .subject-selected strong{
  font-size:19px;
}
.screen-board .board-card{
  padding:9px 4px 10px;
  margin-bottom:9px;
}
.screen-board .board-meta{
  padding:0 7px 5px;
}
.screen-board .tower-board{
  gap:0;
  min-height:0;
  padding:3px 0 4px;
}
.screen-board .tower-row{
  gap:0;
  min-height:var(--tile);
}
.screen-board .btn.full[data-reselect]{
  min-height:48px;
}
.tower-fixed{
  gap:0;
}
.place-preview-board .tower-frame{
  border-color:#d2dbe5;
  background:rgba(255,255,255,.5);
}

@media(max-width:390px){
  .screen-board{--tile:clamp(27px,8.65vw,36px)}
  .screen-board .tower-cell{width:var(--tile);height:var(--tile)}
  .screen-board .subject-selected img{width:42px;height:42px}
  .screen-board .subject-selected strong{font-size:18px}
}


/* Inline placement flow: choose textbook -> legal slots -> confirm, all on hand screen */
.screen-hand .board-selecting{
  border-color:#8ed5ff;
  box-shadow:0 10px 26px rgba(34,139,211,.16);
}
.screen-hand .board-selecting .board-meta span:first-child{
  color:#1478c8;
  font-size:13px;
}
.screen-hand .tower-slot{
  position:relative;
  border:3px solid #2aa7f2;
  background:#e9f8ff;
  color:#0876c4;
  box-shadow:0 0 0 3px rgba(93,194,255,.2),0 0 16px rgba(47,168,239,.35);
  animation:legalSlotPulse .8s ease-in-out infinite alternate;
}
.screen-hand .tower-slot span{
  font-size:clamp(22px,6vw,30px);
  transform:none;
}
@keyframes legalSlotPulse{
  from{transform:scale(.92);filter:brightness(.98)}
  to{transform:scale(1.06);filter:brightness(1.08)}
}
.screen-hand .hand-book.selected{
  border-color:#ffd154;
  background:rgba(255,204,49,.22);
  box-shadow:0 0 0 3px rgba(255,209,84,.18),0 6px 16px rgba(0,0,0,.18);
  transform:translateY(-2px);
}
.screen-hand .hand-book.selected span{
  color:#ffe68e;
}
.inline-selection-status,
.inline-place-confirm{
  width:100%;
  margin:-2px 0 10px;
  border-radius:17px;
  background:rgba(255,253,249,.98);
  border:2px solid #8ed5ff;
  box-shadow:0 8px 20px rgba(31,43,62,.09);
}
.inline-selection-status{
  display:grid;
  grid-template-columns:50px minmax(0,1fr) auto;
  gap:9px;
  align-items:center;
  padding:9px 10px;
}
.inline-selection-status img,
.inline-place-title img{
  width:48px;
  height:48px;
  object-fit:contain;
}
.inline-selection-status strong,
.inline-place-title strong{
  display:block;
  font-size:16px;
  line-height:1.25;
}
.inline-selection-status span,
.inline-place-title span{
  display:block;
  margin-top:2px;
  color:#657185;
  font-size:11px;
  font-weight:850;
  line-height:1.4;
}
.inline-clear{
  border:0;
  border-radius:12px;
  background:#edf2f7;
  color:#526075;
  min-height:38px;
  padding:7px 10px;
  font-weight:950;
}
.inline-place-confirm{
  padding:10px;
  border-color:#f5ba32;
  background:linear-gradient(145deg,#fff9df,#fff);
}
.inline-place-title{
  display:grid;
  grid-template-columns:50px minmax(0,1fr);
  gap:9px;
  align-items:center;
  margin-bottom:9px;
}
.inline-place-actions{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}
.inline-place-actions .btn{
  min-height:45px;
  padding:9px 8px;
}
.tower-preview-choice{
  position:relative;
  z-index:3;
}
.tower-preview-choice::before{
  content:"";
  position:absolute;
  inset:1px;
  border:3px solid #ff9f1a;
  border-radius:11px;
  background:rgba(255,222,110,.28);
  box-shadow:0 0 0 3px rgba(255,255,255,.9),0 0 18px rgba(255,143,0,.5);
  animation:chosenPlacePulse .8s ease-in-out infinite alternate;
}
.tower-preview-choice .tower-book{
  position:relative;
  z-index:2;
}
.inline-preview-here{
  position:absolute;
  z-index:4;
  top:-15px;
  left:50%;
  transform:translateX(-50%);
  padding:3px 6px;
  border-radius:999px;
  background:#ff9218;
  color:#fff;
  font-size:9px;
  font-weight:1000;
  line-height:1;
  white-space:nowrap;
  box-shadow:0 2px 6px rgba(0,0,0,.18);
}
@keyframes chosenPlacePulse{
  from{transform:scale(.95);opacity:.82}
  to{transform:scale(1.04);opacity:1}
}
@media(max-width:390px){
  .inline-selection-status{
    grid-template-columns:42px minmax(0,1fr) auto;
    gap:7px;
    padding:8px;
  }
  .inline-selection-status img,
  .inline-place-title img{
    width:40px;
    height:40px;
  }
  .inline-selection-status strong,
  .inline-place-title strong{
    font-size:14px;
  }
  .inline-selection-status span,
  .inline-place-title span{
    font-size:10px;
  }
  .inline-clear{
    padding:6px 8px;
    font-size:12px;
  }
}


/* Rule visual fixes: keep arrows inline and textbook sizes equal */
.rule-base-row{
  width:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:5px;
  flex-wrap:nowrap;
  white-space:nowrap;
}
.rule-base-row img{
  flex:0 0 auto;
  width:clamp(42px,10.5vw,58px);
  height:clamp(42px,10.5vw,58px);
  object-fit:contain;
}
.rule-arrow{
  flex:0 0 auto;
  display:block;
  font-size:clamp(25px,7vw,34px);
  font-weight:1000;
  line-height:1;
  color:#1b254b;
}
.rule-upper-visual{
  display:grid;
  justify-items:center;
  gap:6px;
}
.rule-upper-bottom{
  display:flex;
  justify-content:center;
  gap:6px;
}
.rule-upper-book{
  width:76px !important;
  height:76px !important;
  object-fit:contain;
}
@media(max-width:520px){
  .rule-base-row{gap:3px}
  .rule-base-row img{
    width:clamp(40px,10.2vw,48px);
    height:clamp(40px,10.2vw,48px);
  }
  .rule-upper-book{
    width:68px !important;
    height:68px !important;
  }
}


/* Rules screen: fit every how-to page in one viewport without scrolling */
.screen-rules{
  min-height:100dvh;
  height:100dvh;
  overflow:hidden;
  display:grid;
  grid-template-rows:auto auto auto minmax(0,1fr) auto;
  align-content:stretch;
  gap:7px;
  padding-top:10px;
  padding-bottom:10px;
}
.screen-rules .top-nav{
  margin:0;
}
.screen-rules .nav-pill{
  padding:8px 12px;
  min-height:40px;
}
.screen-rules .screen-heading{
  margin:2px 0 0;
}
.screen-rules .screen-heading h1{
  font-size:clamp(27px,4.7dvh,36px);
  margin-bottom:2px;
  line-height:1.08;
}
.screen-rules .screen-heading p{
  font-size:clamp(13px,2.15dvh,17px);
  line-height:1.25;
}
.screen-rules .rule-progress{
  margin:0;
  font-size:clamp(14px,2.1dvh,18px);
  line-height:1.2;
}
.screen-rules .rule-card{
  min-height:0;
  height:100%;
  overflow:hidden;
  display:grid;
  grid-template-rows:minmax(105px,1fr) auto auto;
  align-content:stretch;
  gap:7px;
  margin:0;
  padding:11px 13px;
}
.screen-rules .rule-visual{
  min-height:0;
  height:100%;
  max-height:none;
  margin:0;
  padding:8px 10px;
  border-radius:17px;
}
.screen-rules .rule-card h2{
  margin:0;
  font-size:clamp(21px,3.1dvh,28px);
  line-height:1.22;
}
.screen-rules .rule-card p{
  margin:0;
  font-size:clamp(12px,1.9dvh,16px);
  line-height:1.45;
}
.screen-rules > .grid2{
  gap:8px;
}
.screen-rules > .grid2 .btn{
  min-height:46px;
  padding:9px 12px;
}
.screen-rules .rule-visual .mini-books img{
  width:clamp(38px,7.4dvh,52px);
  height:clamp(38px,7.4dvh,52px);
}
.screen-rules .rule-base-row img{
  width:clamp(38px,7.4dvh,52px);
  height:clamp(38px,7.4dvh,52px);
}
.screen-rules .rule-upper-book{
  width:clamp(54px,9.5dvh,68px) !important;
  height:clamp(54px,9.5dvh,68px) !important;
}
@media(max-height:700px){
  .screen-rules{
    gap:5px;
    padding-top:7px;
    padding-bottom:7px;
  }
  .screen-rules .nav-pill{
    min-height:36px;
    padding:6px 10px;
    font-size:12px;
  }
  .screen-rules .screen-heading h1{
    font-size:26px;
  }
  .screen-rules .screen-heading p{
    font-size:13px;
  }
  .screen-rules .rule-card{
    grid-template-rows:minmax(90px,1fr) auto auto;
    gap:5px;
    padding:9px 11px;
  }
  .screen-rules .rule-card h2{
    font-size:20px;
  }
  .screen-rules .rule-card p{
    font-size:12px;
    line-height:1.38;
  }
  .screen-rules > .grid2 .btn{
    min-height:42px;
    padding:7px 10px;
  }
}


/* Hand screen rebalance: large pyramid area + compact hand panel */
.screen-hand{
  --tile:clamp(30px,8.3vw,44px);
}
.screen-hand .board-card{
  min-height:44dvh;
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  padding:11px 7px 12px;
  margin-bottom:8px;
}
.screen-hand .board-meta{
  padding:0 8px 6px;
}
.screen-hand .tower-board{
  min-height:0;
  height:100%;
  align-content:center;
  padding:4px 0 6px;
}
.screen-hand .first-placement{
  min-height:0;
  height:100%;
  align-content:center;
  padding-bottom:0;
}
.screen-hand .hand-private{
  padding:10px 8px 9px;
  margin-bottom:8px;
  border-radius:20px;
}
.screen-hand .hand-private .private-head{
  margin-bottom:7px;
  text-align:left;
}
.screen-hand .private-title{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:9px;
  margin-bottom:3px;
}
.screen-hand .hand-avatar{
  width:44px;
  height:44px;
  flex:0 0 44px;
  margin:0;
  font-size:25px;
  border-width:2px;
}
.screen-hand .private-head h2{
  margin:0;
  font-size:clamp(23px,6vw,30px);
  line-height:1.1;
}
.screen-hand .private-head p{
  margin:0;
  text-align:center;
  font-size:clamp(11px,3vw,14px);
  line-height:1.35;
}
.screen-hand .hand-grid{
  gap:4px;
}
.screen-hand .hand-book{
  min-height:96px;
  height:96px;
  padding:4px 1px;
  gap:0;
  border-radius:12px;
  grid-template-areas:
    "img"
    "name"
    "count"
    "status";
  align-content:center;
}
.screen-hand .hand-book img{
  width:clamp(34px,9vw,44px);
  height:clamp(34px,9vw,44px);
}
.screen-hand .hand-book strong{
  font-size:clamp(10px,2.9vw,13px);
  line-height:1.05;
}
.screen-hand .hand-book b{
  font-size:clamp(14px,3.8vw,17px);
  line-height:1.05;
}
.screen-hand .hand-book span{
  font-size:clamp(8px,2.2vw,10px);
  line-height:1;
  margin-top:1px;
}
.screen-hand .inline-selection-status,
.screen-hand .inline-place-confirm{
  margin:0 0 8px;
}
.screen-hand .inline-selection-status{
  min-height:62px;
  grid-template-columns:42px minmax(0,1fr) auto;
  gap:7px;
  padding:7px 8px;
}
.screen-hand .inline-selection-status img,
.screen-hand .inline-place-title img{
  width:40px;
  height:40px;
}
.screen-hand .inline-selection-status strong,
.screen-hand .inline-place-title strong{
  font-size:14px;
}
.screen-hand .inline-selection-status span,
.screen-hand .inline-place-title span{
  font-size:10px;
  line-height:1.3;
}
.screen-hand .inline-clear{
  min-height:34px;
  padding:6px 8px;
}
.screen-hand .inline-place-confirm{
  padding:8px;
}
.screen-hand .inline-place-title{
  grid-template-columns:42px minmax(0,1fr);
  gap:7px;
  margin-bottom:7px;
}
.screen-hand .inline-place-actions .btn{
  min-height:40px;
  padding:7px 7px;
}
@media(max-height:760px){
  .screen-hand .board-card{
    min-height:40dvh;
  }
  .screen-hand .hand-book{
    min-height:88px;
    height:88px;
  }
  .screen-hand .hand-avatar{
    width:40px;
    height:40px;
    flex-basis:40px;
    font-size:23px;
  }
}
@media(max-width:350px){
  .screen-hand .hand-grid{
    grid-template-columns:repeat(5,minmax(0,1fr));
  }
  .screen-hand .hand-book{
    min-height:86px;
    height:86px;
    grid-template-columns:1fr;
    grid-template-areas:"img" "name" "count" "status";
    justify-items:center;
    text-align:center;
    padding:3px 1px;
  }
  .screen-hand .hand-book img{
    width:32px;
    height:32px;
  }
  .screen-hand .hand-book strong{font-size:9px}
  .screen-hand .hand-book b{font-size:13px}
  .screen-hand .hand-book span{font-size:7px}
}


/* Continuous play layout: fixed pyramid + compact handoff panel */
.screen-pass,
.screen-hand,
.screen-noMove{
  --tile:clamp(28px,8.1vw,40px);
}
.play-status{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
  margin:2px 2px 5px;
  padding:0 3px;
}
.play-status strong{
  font-size:clamp(18px,5vw,24px);
  line-height:1.1;
}
.play-status span{
  color:#68758a;
  font-size:clamp(11px,3vw,14px);
  font-weight:900;
  text-align:right;
}
.screen-pass .score-strip,
.screen-hand .score-strip,
.screen-noMove .score-strip{
  margin-bottom:6px;
  padding-bottom:2px;
}
.screen-pass .board-card,
.screen-hand .board-card,
.screen-noMove .board-card{
  min-height:43dvh;
  height:43dvh;
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  margin-bottom:8px;
  padding:10px 6px 10px;
}
.screen-pass .tower-board,
.screen-hand .tower-board,
.screen-noMove .tower-board{
  min-height:0;
  height:100%;
  align-content:center;
  padding:2px 0 4px;
  gap:0;
}
.fixed-pyramid .tower-row{
  min-height:var(--tile);
}
.fixed-pyramid .tower-frame{
  width:calc(var(--tile) - 6px);
  height:calc(var(--tile) - 6px);
}
.fixed-pyramid .tower-book{
  width:calc(var(--tile) - 2px);
  height:calc(var(--tile) - 2px);
}
.fixed-pyramid .tower-slot{
  width:calc(var(--tile) - 6px);
  height:calc(var(--tile) - 6px);
}
.screen-pass .compact-pass{
  min-height:0 !important;
  padding:12px 13px 13px;
  border-radius:20px;
  display:grid;
  place-items:stretch;
  align-content:initial;
  gap:10px;
  text-align:left;
}
.compact-pass-main{
  display:flex;
  align-items:center;
  gap:11px;
  min-width:0;
}
.pass-avatar{
  width:54px;
  height:54px;
  flex:0 0 54px;
  margin:0;
  font-size:30px;
}
.compact-pass-copy{
  min-width:0;
}
.compact-pass-copy h2{
  margin:0 0 3px;
  font-size:clamp(18px,5vw,24px);
  line-height:1.25;
}
.compact-pass-copy p{
  margin:0;
  color:#cbd4e0;
  font-size:12px;
  font-weight:800;
  line-height:1.35;
}
.compact-pass .hold-btn{
  width:100%;
  min-height:48px;
  margin:0;
}
.compact-no-move{
  padding:12px 13px 13px;
  text-align:left;
}
.compact-no-move .compact-pass-copy p{
  color:#68758a;
}
.compact-no-move .penalty-big{
  margin:5px 0 8px;
  text-align:center;
  font-size:30px;
}
.screen-hand .hand-private{
  margin-bottom:0;
}
@media(max-height:760px){
  .screen-pass .board-card,
  .screen-hand .board-card,
  .screen-noMove .board-card{
    min-height:39dvh;
    height:39dvh;
  }
  .pass-avatar{
    width:48px;
    height:48px;
    flex-basis:48px;
    font-size:27px;
  }
  .compact-pass-copy h2{
    font-size:18px;
  }
  .screen-pass .compact-pass{
    padding:10px 11px;
    gap:8px;
  }
  .compact-pass .hold-btn{
    min-height:44px;
  }
}


/* Growing pyramid: only confirmed height is shown until the 8-book base is complete */
.screen-pass .tower-board,
.screen-hand .tower-board,
.screen-noMove .tower-board{
  align-content:end;
}
.growing-pyramid .tower-board{
  align-content:end;
}
.growing-pyramid .tower-row{
  min-height:var(--tile);
}
.growing-pyramid .tower-frame{
  width:calc(var(--tile) - 6px);
  height:calc(var(--tile) - 6px);
}
.growing-pyramid .tower-book{
  width:calc(var(--tile) - 2px);
  height:calc(var(--tile) - 2px);
}
.growing-pyramid .tower-slot{
  width:calc(var(--tile) - 6px);
  height:calc(var(--tile) - 6px);
}


/* Hand selection state stays inside the hand card to prevent layout shift */
.screen-hand .hand-private .private-head{
  min-height:86px;
  display:grid;
  align-content:start;
  gap:6px;
}
.screen-hand .private-title{
  margin-bottom:0;
}
.hand-state-row{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  align-items:center;
  gap:7px;
  min-height:34px;
}
.hand-state-text{
  margin:0;
  color:#c9d3e0;
  font-size:clamp(10px,2.7vw,13px);
  font-weight:800;
  line-height:1.25;
  text-align:center;
}
.hand-state-row .hand-state-text{
  text-align:left;
}
.hand-clear{
  border:0;
  border-radius:10px;
  background:rgba(255,255,255,.12);
  color:#eef3f8;
  min-height:32px;
  padding:5px 9px;
  font-weight:950;
  font-size:11px;
}
.hand-confirm-inline{
  min-height:34px;
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:7px;
}
.hand-confirm-inline .btn{
  min-height:34px;
  padding:5px 7px;
  font-size:12px;
  border-radius:11px;
  box-shadow:none;
}
.screen-hand > .inline-selection-status,
.screen-hand > .inline-place-confirm{
  display:none !important;
}
@media(max-height:760px){
  .screen-hand .hand-private .private-head{
    min-height:80px;
    gap:5px;
  }
  .hand-confirm-inline .btn{
    min-height:32px;
    font-size:11px;
  }
}
