:root{font-family:system-ui,-apple-system,"Yu Gothic",Meiryo,sans-serif;color:#eaf0ff;background:#101827}*{box-sizing:border-box}body{margin:0}main{max-width:1120px;margin:auto;padding:22px 16px 60px}h1{font-size:clamp(23px,4vw,36px);margin:0}h1 small{font-size:13px;color:#9caed0}header p,.note{color:#9caed0;font-size:13px}h2{font-size:19px;margin:0 0 16px}.panel{background:#1b2940;border:1px solid #344663;border-radius:16px;padding:20px;margin:16px 0}.fields{display:grid;grid-template-columns:repeat(auto-fit,minmax(175px,1fr));gap:14px;margin-bottom:18px}label{display:grid;gap:7px;font-size:14px}input,select{width:100%;border:1px solid #546783;border-radius:9px;padding:12px;background:#101c30;color:#fff;font:inherit}button{cursor:pointer;border:1px solid #637797;border-radius:9px;padding:11px 17px;background:#2c3e5d;color:#fff;font:inherit}button:hover{filter:brightness(1.16)}button:disabled{opacity:.45;cursor:default}.primary{background:#2767db;border-color:#4483f0;font-weight:700}.toolbar,.board-head{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap}.toolbar #status{font-weight:700}.players{display:flex;gap:10px;flex-wrap:wrap;margin:14px 0}.player{background:#1b2940;border:1px solid #425472;padding:10px 14px;border-radius:12px}.player.active{border-color:#5aa7ff;box-shadow:0 0 0 1px #5aa7ff}.player.dead{opacity:.5;text-decoration:line-through}.board{display:grid;grid-template-columns:repeat(9,minmax(0,1fr));gap:5px}.cell{position:relative;aspect-ratio:1/1;min-width:0;background:#263b59;border:1px solid #4c6486;border-radius:8px;display:flex;align-items:center;justify-content:center;font-size:clamp(13px,2.6vw,25px);font-weight:700}.cell.filled{background:#23649b}.cell.bomb{border-color:#ef9c6b}.cell.goal{border:2px solid #f5d273}.cell .idx{position:absolute;top:2px;left:4px;font-size:9px;color:#b3c4dd;font-weight:400}.cell .mark{position:absolute;bottom:1px;right:3px;font-size:11px}.entry{display:flex;gap:10px}.entry input{flex:1;min-width:0}.entry button{flex-shrink:0}#message{min-height:24px;color:#ffd07b;font-weight:700}#hint{color:#b6c7e5}.link{background:transparent;border:0;color:#a7caff;padding:0}#history{line-height:1.9;padding-left:25px}#result{border-color:#e9c56b}#result h2{color:#ffda7c}@media(max-width:520px){.panel{padding:13px}.board{gap:3px}.cell{border-radius:4px}.cell .idx{font-size:7px}.cell .mark{font-size:9px}.entry{gap:6px}}

/* STEP 1 update: desktop fixed word entry */
.start-kana{display:flex;align-items:center;gap:14px;margin-bottom:18px;font-weight:700;color:#d3e4ff}
.start-kana strong{display:inline-flex;align-items:center;justify-content:center;width:58px;height:58px;background:#2767db;border:1px solid #72a5ff;border-radius:14px;color:white;font-size:32px}
@media(min-width:768px){
  #game{padding-bottom:235px}
  #game .input-panel{position:fixed;bottom:16px;left:50%;transform:translateX(-50%);width:min(400px,calc(100% - 24px));margin:0;z-index:1000;box-shadow:0 -10px 35px rgba(0,0,0,.55);padding:14px 16px 12px;background:#20314c}
  #game .input-panel h2{margin-bottom:9px}
  #game .input-panel #hint,#game .input-panel #message{margin:7px 0 0;min-height:0;font-size:13px}
}

/* STEP 2-1: local player name entry */
.name-fields{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:14px;margin:0 0 12px}
.name-error{color:#ffb0b0;font-weight:700;min-height:1.3em;margin:0 0 10px}

/* STEP 2-2: local room-code preview */
.room-preview{border:1px solid #4d6789;background:#142238;border-radius:12px;padding:16px;margin:10px 0 18px}
.room-preview h3{margin:0 0 8px;font-size:17px}
.room-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin:10px 0}
.room-actions input{flex:1 1 230px;min-width:0}
.room-code{font-size:26px;letter-spacing:3px;font-variant-numeric:tabular-nums;color:#ffda7c}
@media(max-width:520px){.room-actions button{flex:1 1 auto}}

/* STEP 2-3⑩: online join controls */
.join-label{flex:1 1 220px;min-width:0}
#roomMessage{white-space:pre-wrap;overflow-wrap:anywhere}

.my-rooms{margin-top:16px;padding-top:12px;border-top:1px solid #7775}.my-rooms h3{margin:0}.saved-room-item{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px;padding:10px 0;border-bottom:1px solid #7774}.saved-room-item span{overflow-wrap:anywhere}

.online-participants{margin-top:16px;padding:12px;border:1px solid #65748b;border-radius:8px}.online-participants ul{margin:8px 0;padding-left:22px}.online-participants li{margin:5px 0}

/* Cute title-screen refresh: existing game/online element IDs and JS retained */
:root{color:#382d31;background:#e6f9ff}
body{background:linear-gradient(180deg,#74d8ff 0,#e5faff 650px,#f4fcff 100%);color:#382d31}
main{max-width:1200px;padding-top:0}
.top-header{height:0;overflow:hidden}
.title-screen{position:relative;aspect-ratio:1648/928;margin:0 -16px 20px;background:url('top-visual.png') center center/100% 100% no-repeat;border-radius:0 0 28px 28px;overflow:hidden;filter:drop-shadow(0 9px 12px #245c7950)}
.title-menu{position:absolute;left:26%;top:39%;width:48%;height:50%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4%;padding:3% 2.5%;background:linear-gradient(155deg,#fffbdc 0%,#fff8bf 100%);border:5px solid #ffdc54;border-radius:8%;box-shadow:0 0 0 3px #a05b1a,0 6px 0 #a05b1a,inset 0 0 22px #fff;}
.title-menu:before,.title-menu:after{content:'🐾';position:absolute;color:#ffca32;font-size:clamp(14px,2vw,25px);top:11%}.title-menu:before{left:4%}.title-menu:after{right:4%}
.title-action{display:block;width:90%;height:29%;padding:0 6px;min-height:0;border-radius:999px;border:3px solid #fff;box-shadow:0 4px 0 #74462c,0 0 0 2px #6e321d,inset 0 3px 9px #ffffff8a;font-size:clamp(11px,2.1vw,27px);font-weight:900;letter-spacing:.02em;text-shadow:0 2px 1px #532c31;color:white;white-space:nowrap}
.title-create{background:linear-gradient(#ff7ba1,#f2185a);border-color:#ffe4ed}
.title-join{background:linear-gradient(#65d7ff,#0876ef);border-color:#d6f8ff}
.title-watch{background:linear-gradient(#ffe973,#ffb91b);color:#783a1a;text-shadow:0 1px #fff6b0;opacity:1;cursor:not-allowed}
.title-watch:disabled{opacity:1;filter:saturate(.7)}
.coming-soon{font-size:.48em;vertical-align:middle;background:#fff8dc;color:#79552c;padding:2px 5px;border-radius:99px;text-shadow:none}
.panel{background:#fffdf4;border:2px solid #ffda79;box-shadow:0 5px 0 #e8d39e,0 8px 18px #35617d18;color:#43303a;border-radius:22px}
#setup{scroll-margin-top:20px}
.setup-intro{margin:0 0 12px;color:#e17563;font-weight:800}
h2,h3{color:#8a4b28}.note,header p{color:#6c7483}
label{font-weight:650}
input,select{background:#fff;color:#382d31;border:2px solid #c7d7e9;border-radius:12px}
input:focus-visible,select:focus-visible,button:focus-visible{outline:3px solid #ffab35;outline-offset:2px}
button{border:2px solid #a8c9e6;border-radius:12px;background:linear-gradient(#fff,#e5f5ff);color:#315378;font-weight:750}
button:disabled{opacity:.55}
.primary{background:linear-gradient(#6ed4ff,#1681eb);color:white;border-color:#2178cb}
.room-preview{background:#fff8e6;border:2px solid #f3d68e;border-radius:18px}
.room-code{color:#d76b21}
.my-rooms{border-top-color:#ead7a7}
.saved-room-item{border-bottom-color:#e6d6b2}
.online-participants{background:#fff;border-color:#c7d7e9;border-radius:14px}
.name-error{color:#c43147}
.player{background:#fff;border-color:#a9cde7}.player.active{border-color:#008fe8}
.cell{background:#e5f5ff;border-color:#9ecfe6;color:#42324b}.cell.filled{background:#84dcff}.cell.bomb{border-color:#f7a352}.cell.goal{border-color:#ffb626}
.start-kana{color:#48667b}.start-kana strong{background:#26a9ed;border-color:#a3e6ff}
#hint{color:#5b6f8a}#message{color:#b86315}.link{color:#1779c6}
#game .input-panel{background:#fffdf4;box-shadow:0 6px 30px #245c7955}
.menu-focus{animation:focusGlow 1.6s ease-out}
@keyframes focusGlow{0%,60%{box-shadow:0 0 0 5px #ffad36,0 0 0 10px #ffdb8770}100%{box-shadow:none}}
@media(max-width:700px){
 .title-screen{aspect-ratio:auto;height:390px;background-size:auto 390px;background-position:center top;border-radius:0 0 20px 20px}
 .title-menu{left:12%;width:76%;top:42%;height:52%;border-width:3px;gap:5%;padding:4% 2%;border-radius:22px}
 .title-action{font-size:clamp(14px,3.6vw,22px);height:29%;border-width:2px}
 .title-menu:before,.title-menu:after{font-size:13px;top:8%}
}
@media(max-width:380px){.title-screen{height:345px;background-size:auto 345px}.title-action{font-size:13px}.title-menu{top:43%;height:51%}}
@media(prefers-reduced-motion:reduce){html{scroll-behavior:auto}.menu-focus{animation:none}}

/* URL-based page separation: preserve existing element IDs and event handlers. */
.page-nav{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:18px}
.home-link{display:inline-block;padding:10px 16px;border-radius:14px;background:#e5f6ff;color:#1764a0;text-decoration:none;font-weight:800;border:2px solid #aad9f2}
#pageTitle{font-weight:900;color:#ae5b24}
body[data-page="home"] #setup{display:none}
body[data-page="create"] .title-screen,body[data-page="join"] .title-screen{display:none}
body[data-page="join"] #createSettings,body[data-page="join"] #createSection,body[data-page="join"] #localStartSection{display:none}
body[data-page="create"] #joinRoomArea{display:none}
body.in-game #setup{display:none!important}
body.in-game .title-screen{display:none!important}
body[data-page="create"] #setup,body[data-page="join"] #setup{max-width:850px;margin:20px auto}
body[data-page="join"] #setup .setup-intro{display:none}

/* TOP only: balance free space above and below the title visual. */
body[data-page="home"] #app:not(:has(#game:not([hidden]))){
  min-height:100vh;
  min-height:100svh;
  display:flex;
  flex-direction:column;
  justify-content:center;
  padding:16px;
}
body[data-page="home"]:not(.in-game) .title-screen{
  width:min(100%, calc((100svh - 32px) * 1648 / 928));
  margin:0 auto;
  flex:none;
  border-radius:24px;
}
@media(max-width:700px){
  body[data-page="home"]:not(.in-game) .title-screen{
    width:100%;
    height:min(390px, calc(100svh - 32px));
    background-size:auto 100%;
  }
}
@media(max-width:380px){
  body[data-page="home"]:not(.in-game) .title-screen{
    height:min(345px, calc(100svh - 32px));
  }
}

/* Game settings: keep all five controls on a single horizontal row. */
#createSettings .fields{grid-template-columns:repeat(5,minmax(0,1fr));gap:10px}
#createSettings .fields>label{min-width:0}
#createSettings .fields input,#createSettings .fields select{min-width:0;width:100%}
@media(max-width:680px){
  #createSettings .fields{grid-template-columns:repeat(5,minmax(135px,1fr));overflow-x:auto;padding-bottom:8px}
}

/* Official mascots on create/join pages. Decorative only; forms remain usable. */
body[data-page="create"] #setup,body[data-page="join"] #setup{position:relative;isolation:isolate}
.side-mascot{display:none;position:absolute;top:105px;width:clamp(120px,14vw,195px);height:auto;pointer-events:none;user-select:none;filter:drop-shadow(0 9px 9px #41637d44);z-index:2}
@media(min-width:1050px){
 body[data-page="create"] .side-mascot,body[data-page="join"] .side-mascot{display:block}
 .side-mascot-cat{right:calc(100% + 14px)}
 .side-mascot-dog{left:calc(100% + 14px)}
}
@media(min-width:1120px) and (max-width:1290px){.side-mascot{width:clamp(105px,11vw,150px)}}

/* Mascots are outside the form panel, but must paint above the page background. */
body[data-page="create"] #setup,body[data-page="join"] #setup{overflow:visible}
@media(min-width:1050px) and (max-width:1200px){.side-mascot{width:clamp(72px,9vw,112px)}.side-mascot-cat{right:calc(100% + 4px)}.side-mascot-dog{left:calc(100% + 4px)}}

/* Mascot placement v2: both routed screens, pinned to viewport on scroll. */
@media (min-width:1050px){
  body[data-page="create"] #setup > .side-mascot,
  body[data-page="join"] #setup > .side-mascot{
    display:block !important;
    position:fixed !important;
    top:50vh !important;
    top:50dvh !important;
    transform:translateY(-50%);
    width:clamp(80px, calc((100vw - 900px)/2 - 24px), 205px);
    max-height:78vh;
    object-fit:contain;
    z-index:20;
    pointer-events:none;
  }
  body[data-page="create"] #setup > .side-mascot-cat,
  body[data-page="join"] #setup > .side-mascot-cat{left:clamp(8px, 2vw, 36px) !important;right:auto !important}
  body[data-page="create"] #setup > .side-mascot-dog,
  body[data-page="join"] #setup > .side-mascot-dog{right:clamp(8px, 2vw, 36px) !important;left:auto !important}
}
@media(max-width:1049px){#setup > .side-mascot{display:none !important}}

/* Online room creation: coordinated blue palette, no conflicting gold outline. */
#createRoom.create-room-cta{
  display:block;flex:0 0 100%;width:100%;max-width:520px;
  margin:8px auto 14px;padding:18px 24px;
  appearance:none;border:2px solid #2378c6;border-radius:16px;
  background:linear-gradient(180deg,#67d4ff 0%,#299eea 54%,#1478d1 100%);
  color:#fff;font-size:clamp(17px,2.2vw,22px);font-weight:900;
  letter-spacing:.03em;text-shadow:0 1px 2px rgba(16,68,123,.45);
  box-shadow:0 5px 0 #155a9b,0 9px 18px rgba(35,110,165,.2);
  transition:filter .15s,transform .15s,box-shadow .15s;
}
#createRoom.create-room-cta:hover:not(:disabled){filter:brightness(1.06);transform:translateY(-2px);box-shadow:0 7px 0 #155a9b,0 12px 20px rgba(35,110,165,.23)}
#createRoom.create-room-cta:active:not(:disabled){transform:translateY(3px);box-shadow:0 2px 0 #155a9b,0 4px 9px rgba(35,110,165,.18)}
#createRoom.create-room-cta:disabled{opacity:.55;box-shadow:none}

.start-match-area{margin-top:16px;text-align:center}.start-match-area button{width:100%;max-width:360px;padding:14px;font-size:18px;font-weight:700}.start-match-area .note{margin-top:6px}

/* STEP 4-2/4-3: start button only for room creator; clearly legible disabled state */
#startMatchArea[hidden]{display:none!important}
#startMatch{
  opacity:1!important;
  background:#e5e7eb!important;
  border:2px solid #bfc5ce!important;
  color:#596475!important;
  text-shadow:none!important;
  box-shadow:none!important;
  cursor:not-allowed;
}
#startMatch.is-ready{
  background:#2563eb!important;
  border-color:#1d4ed8!important;
  color:#fff!important;
}
