* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #1a1626; overflow: hidden; }
body { font-family: "Courier New", ui-monospace, monospace; color: #f2ecdc;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; }

#stage { position: relative; width: 960px; max-width: 100vw; }
#game { display: block; width: 100%; max-height: 100dvh; object-fit: contain;
  image-rendering: pixelated; background: #101018;
  border: 4px solid #3a2f52; border-radius: 6px; touch-action: none; }

/* ---------- HUD ---------- */
#hud { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 10px;
  align-items: center; pointer-events: none; font-weight: bold; text-shadow: 1px 1px 0 #000; }
#clockbox { background: rgba(20,16,34,.85); padding: 4px 10px; border-radius: 8px;
  border: 2px solid #57487e; font-size: 15px; }
#moneybox { background: rgba(20,16,34,.85); padding: 4px 10px; border-radius: 8px;
  border: 2px solid #b89a3c; font-size: 15px; color: #ffe27a; }
.meter { display: flex; align-items: center; gap: 4px; }
.mlabel { font-size: 14px; }
.mbar { width: 90px; height: 12px; background: #241d38; border: 2px solid #57487e;
  border-radius: 6px; overflow: hidden; }
.mbar.big { width: 100%; height: 18px; }
.mfill { height: 100%; width: 50%; transition: width .3s; }
.mfill.energy { background: linear-gradient(#ffe27a,#f5a623); }
.mfill.fun { background: linear-gradient(#7ae0ff,#2f9de0); }
.mfill.radar { background: linear-gradient(#ff9d7a,#e0472f); }
.mfill.you { background: linear-gradient(#7ae0ff,#2f9de0); }
.mfill.foe { background: linear-gradient(#ffa1c9,#e0479d); }
#hud button { pointer-events: auto; margin-left: auto; background: #57487e; color: #fff;
  border: 2px solid #7d68b3; border-radius: 8px; padding: 4px 10px; font: inherit;
  font-size: 13px; cursor: pointer; }
#hud button:hover { background: #6d5a9c; }
#hud button + button { margin-left: 0; }

/* ---------- Dialog ---------- */
.hidden { display: none !important; }
#dialog { position: absolute; left: 4%; right: 4%; bottom: 14px; z-index: 6;
  background: rgba(16,12,30,.94); border: 3px solid #7d68b3; border-radius: 12px;
  padding: 12px 16px; min-height: 110px; }
#d-name { color: #ffd764; font-weight: bold; font-size: 15px; margin-bottom: 4px; }
#d-text { font-size: 15px; line-height: 1.45; white-space: pre-wrap; }
#d-options { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
#d-options .opt { padding: 3px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; }
#d-options .opt.sel { background: #57487e; }
#d-options .opt:hover { background: #453768; }
#d-hint { position: absolute; right: 12px; bottom: 6px; font-size: 11px; color: #8f82ae; }

/* ---------- Panels ---------- */
#panel { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); z-index: 6;
  width: min(560px, 92%); max-height: 78%; overflow-y: auto;
  background: rgba(16,12,30,.96); border: 3px solid #7d68b3; border-radius: 12px; padding: 14px; }
#p-title { color: #ffd764; font-size: 17px; font-weight: bold; margin-bottom: 8px; }
#p-body { font-size: 14px; line-height: 1.5; }
#p-body .skillrow { margin-bottom: 8px; }
#p-body .skillrow .sname { display: flex; justify-content: space-between; }
#p-body .title { color: #9ce09a; }
#p-close { margin-top: 10px; background: #57487e; color: #fff; border: 2px solid #7d68b3;
  border-radius: 8px; padding: 4px 12px; font: inherit; cursor: pointer; }
.qdone { color: #9ce09a; }
.qopen { color: #ffd764; }

/* ---------- Battle ---------- */
#battle { position: absolute; top: 40px; left: 50%; transform: translateX(-50%); z-index: 6;
  width: min(600px, 94%); background: rgba(16,12,30,.97); border: 3px solid #e0479d;
  border-radius: 12px; padding: 14px; }
#b-title { color: #ffa1c9; font-weight: bold; font-size: 17px; text-align: center; margin-bottom: 8px; }
.b-row { display: flex; gap: 16px; }
.b-col { flex: 1; }
.b-name { font-weight: bold; margin-bottom: 2px; }
.b-sub { font-size: 11px; color: #8f82ae; }
#b-log { background: #241d38; border-radius: 8px; margin: 10px 0; padding: 8px 10px;
  height: 120px; overflow-y: auto; font-size: 13px; line-height: 1.45; }
#b-moves { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#b-moves button { background: #57487e; color: #fff; border: 2px solid #7d68b3;
  border-radius: 8px; padding: 8px; font: inherit; font-size: 14px; cursor: pointer; }
#b-moves button:hover:not(:disabled) { background: #6d5a9c; }
#b-moves button:disabled { opacity: .4; cursor: default; }

/* ---------- Minigame ---------- */
#minigame { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 6;
  width: min(520px, 92%); background: rgba(16,12,30,.97); border: 3px solid #2f9de0;
  border-radius: 12px; padding: 18px; text-align: center; }
#minigame h3 { color: #7ae0ff; margin-bottom: 8px; }
#minigame .track { position: relative; height: 26px; background: #241d38; border-radius: 8px;
  margin: 12px 0; overflow: hidden; }
#minigame .zone { position: absolute; top: 0; bottom: 0; background: rgba(120,224,120,.45); }
#minigame .cursor { position: absolute; top: 0; bottom: 0; width: 6px; background: #ffd764; }
#minigame .mash { font-size: 34px; letter-spacing: 6px; }
#minigame button { background: #57487e; color: #fff; border: 2px solid #7d68b3;
  border-radius: 8px; padding: 8px 16px; font: inherit; cursor: pointer; margin-top: 8px; }

/* ---------- Toasts ---------- */
#toasts { position: absolute; top: 46px; right: 10px; z-index: 7; display: flex; flex-direction: column;
  gap: 6px; align-items: flex-end; pointer-events: none; }
.toast { background: rgba(20,16,34,.92); border: 2px solid #9ce09a; color: #d8f5d6;
  border-radius: 10px; padding: 6px 12px; font-size: 13px; animation: tin .25s ease-out;
  max-width: 340px; }
.toast.bad { border-color: #e0725f; color: #ffd9cf; }
.toast.gold { border-color: #ffd764; color: #ffedb3; }
@keyframes tin { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Title ---------- */
#title-screen { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 30%, #35295a, #17111f 75%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; border-radius: 6px; z-index: 10; }
#title-screen h1 { font-size: 54px; line-height: 1.05; color: #ffd764;
  text-shadow: 3px 3px 0 #a3405f, 6px 6px 0 rgba(0,0,0,.4); letter-spacing: 2px; }
#title-screen .tag { color: #cbbfe8; font-size: 15px; }
#title-screen .cast { color: #8f82ae; font-size: 12px; }
#title-screen button { background: #e0479d; color: #fff; border: 3px solid #ffa1c9;
  border-radius: 12px; padding: 10px 26px; font: inherit; font-size: 18px; font-weight: bold;
  cursor: pointer; }
#title-screen button:hover { transform: scale(1.05); }
#title-screen .pick { color: #ffd764; font-size: 14px; letter-spacing: 2px; }
#char-grid { display: grid; grid-template-columns: repeat(4, 96px); gap: 10px; justify-content: center; }
#char-grid .charbtn { background: #2b2246; border: 3px solid #57487e; border-radius: 12px;
  padding: 8px 4px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center;
  gap: 4px; color: #f2ecdc; font: inherit; font-size: 13px; font-weight: bold; }
#char-grid .charbtn:hover:not(:disabled) { border-color: #ffd764; transform: scale(1.06); }
#char-grid .charbtn canvas { image-rendering: pixelated; width: 48px; height: 48px; }
#char-grid .charbtn:disabled { opacity: .45; cursor: not-allowed; }
#char-grid .charbtn small { font-weight: normal; color: #8f82ae; font-size: 10px; }
#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none;
  transition: opacity .22s; border-radius: 6px; z-index: 8; }
#fade.on { opacity: 1; }
.career-row { margin-bottom: 8px; padding: 6px 8px; background: #241d38; border-radius: 8px; }
.career-row .cjob { color: #ffd764; font-weight: bold; }
.career-row .cnext { color: #8f82ae; font-size: 12px; }
.trophy { color: #ffd764; font-size: 15px; margin-bottom: 8px; }
#title-screen .tiny { font-size: 11px; color: #6f6390; }

/* ---------- Touch controls ---------- */
#touch { display: none; }
@media (pointer: coarse) {
  #touch { display: block; }
  #dpad { position: absolute; left: 12px; bottom: 12px; width: 132px; height: 132px; }
  #dpad button { position: absolute; width: 44px; height: 44px; background: rgba(87,72,126,.75);
    border: 2px solid #7d68b3; border-radius: 10px; color: #fff; font-size: 18px; }
  #dpad button[data-d="up"] { left: 44px; top: 0; }
  #dpad button[data-d="left"] { left: 0; top: 44px; }
  #dpad button[data-d="right"] { left: 88px; top: 44px; }
  #dpad button[data-d="down"] { left: 44px; top: 88px; }
  #abtn { position: absolute; right: 16px; bottom: 26px; width: 64px; height: 64px;
    border-radius: 50%; background: rgba(224,71,157,.8); border: 3px solid #ffa1c9;
    color: #fff; font-size: 24px; font-weight: bold; }
}

/* ---------- Multiplayer ---------- */
#joinbox { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: min(400px, 92%); background: rgba(16,12,30,.97); border: 3px solid #2f9de0;
  border-radius: 12px; padding: 18px; text-align: center; z-index: 20; }
#joinbox h3 { color: #7ae0ff; margin-bottom: 6px; }
#joinbox p { font-size: 13px; color: #cbbfe8; margin-bottom: 10px; }
#j-code { width: 80%; padding: 10px; font: inherit; font-size: 18px; text-align: center;
  letter-spacing: 3px; text-transform: uppercase; background: #241d38; color: #ffd764;
  border: 2px solid #57487e; border-radius: 8px; margin-bottom: 8px; }
#j-err { color: #ff9d7a; font-size: 13px; min-height: 18px; margin-bottom: 4px; }
#joinbox button { display: block; width: 80%; margin: 6px auto 0; background: #2f9de0;
  color: #fff; border: 2px solid #7ae0ff; border-radius: 8px; padding: 9px; font: inherit;
  font-weight: bold; cursor: pointer; }
#joinbox button#j-solo { background: #57487e; border-color: #7d68b3; font-weight: normal; }
#chat { position: absolute; right: 8px; bottom: 8px; width: min(300px, 60%); z-index: 4;
  display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#chatlog { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
#chatlog .cline { background: rgba(16,12,30,.82); border-radius: 8px; padding: 3px 8px;
  font-size: 12px; max-width: 100%; }
#chatlog .cline b { color: #ffd764; }
#chatbar { pointer-events: auto; background: rgba(16,12,30,.95); border: 2px solid #57487e;
  border-radius: 10px; padding: 6px; }
#chatpresets { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 5px; }
#chatpresets button { background: #57487e; color: #fff; border: none; border-radius: 12px;
  padding: 3px 9px; font: inherit; font-size: 12px; cursor: pointer; }
#chatrow { display: flex; gap: 4px; }
#chatmsg { flex: 1; padding: 6px 8px; font: inherit; font-size: 13px; background: #241d38;
  color: #f2ecdc; border: 2px solid #57487e; border-radius: 8px; min-width: 0; }
#chatsend { background: #2f9de0; color: #fff; border: none; border-radius: 8px;
  padding: 0 12px; font: inherit; cursor: pointer; }
#chatbtn { position: absolute; right: 14px; bottom: 110px; width: 44px; height: 44px;
  border-radius: 50%; background: rgba(47,157,224,.85); border: 2px solid #7ae0ff;
  font-size: 20px; z-index: 4; cursor: pointer; display: none; }
@media (pointer: coarse) { #chatbtn.mp { display: block; } }
@media (pointer: fine) { #chatbtn.mp { display: block; } }

@media (pointer: coarse) {
  #chat { bottom: 176px; }
}

/* mobile overrides — keep LAST so they win the cascade */
@media (max-width: 700px) {
  #stage { width: 100vw; }
  #title-screen { position: fixed; inset: 0; border-radius: 0; overflow-y: auto; padding: 14px 12px; gap: 10px; }
  #title-screen .tag, #title-screen .tiny { padding: 0 10px; }
  #joinbox { position: fixed; }
  #hud { flex-wrap: wrap; gap: 5px; row-gap: 4px; }
  #toasts { top: 92px; }
  #char-grid { grid-template-columns: repeat(4, 76px); gap: 6px; }
  #char-grid .charbtn { padding: 5px 2px 4px; font-size: 11px; }
  #char-grid .charbtn canvas { width: 36px; height: 36px; }
  #moneybox { font-size: 12px; }
  #title-screen h1 { font-size: 34px; }
  #game { border-left: none; border-right: none; border-radius: 0; }
  #clockbox { font-size: 12px; }
  .mbar { width: 54px; }
  #hud button { font-size: 11px; padding: 3px 7px; }
  #d-text { font-size: 14px; }
  #d-options .opt { padding: 8px 10px; font-size: 14px; }
  #d-hint { display: none; }
  #b-moves button { padding: 12px 8px; }
  #minigame button { padding: 12px 20px; }
}
