:root{
  --bg:#070b14;
  --panel:#0d1426;
  --stroke:rgba(255,255,255,.10);
  --text:rgba(234,240,255,.92);
  --muted:rgba(234,240,255,.70);
  --accent:#6fb1ff;
  --ok:#34c759;
  --warn:#ff9f0a;
  --bad:#ff453a;
}

*{box-sizing:border-box}

body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background:
    radial-gradient(1200px 600px at 30% 10%, rgba(111,177,255,.16), transparent 55%),
    radial-gradient(900px 500px at 70% 20%, rgba(52,199,89,.10), transparent 60%),
    var(--bg);
  color:var(--text);
}

.top{
  padding:16px 18px;
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:12px;
}

.title{font-weight:900;font-size:18px;letter-spacing:.2px}
.subtitle{margin-top:6px;color:var(--muted);font-size:12px;line-height:1.35}

.hints{color:var(--muted);font-size:12px;line-height:1.35}
.pill{display:inline-block;padding:2px 8px;border:1px solid rgba(255,255,255,.12);border-radius:999px;background:rgba(255,255,255,.04);color:rgba(234,240,255,.86);font-weight:900}

.playerTag{
  align-self:flex-start;
  padding:6px 10px;
  border:1px solid rgba(255,255,255,.12);
  border-radius:999px;
  background:rgba(255,255,255,.04);
  color:rgba(234,240,255,.86);
  font-size:12px;
  font-weight:900;
  white-space:nowrap;
}

.wrap{padding:0 18px 18px;display:grid;grid-template-columns: 1fr 320px;gap:14px;align-items:start}
@media (max-width: 1100px){
  .wrap{grid-template-columns:1fr}
}

.frame[hidden]{
  display:none;
}

#gameFrame:not([hidden]){
  display:contents;
}

#mapFrame{
  grid-column: 1 / -1;
}

.wrap > section{grid-column:1}
.wrap > .rightPanel{grid-column:2}

@media (max-width: 1100px){
  .wrap > section{grid-column:auto}
  .wrap > .rightPanel{grid-column:auto}
}

.card{
  border:1px solid rgba(255,255,255,.08);
  border-radius:18px;
  background:rgba(13,20,38,.55);
  overflow:hidden;
}

.cardHead{
  padding:12px 14px;
  border-bottom:1px solid rgba(255,255,255,.08);
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:12px;
}

.cardTitle{font-weight:900;letter-spacing:.2px}
.cardHint{color:var(--muted);font-size:12px;line-height:1.35}
.cardBody{padding:12px 14px}

.levelRow{
  display:flex;
  align-items:baseline;
  gap:10px;
  flex-wrap:wrap;
}

.levelPlayer{
  padding:3px 8px;
  border:1px solid rgba(255,255,255,.12);
  border-radius:999px;
  background:rgba(255,255,255,.04);
  color:rgba(234,240,255,.86);
  font-size:12px;
  font-weight:900;
}

.gameBody{
  display:flex;
  justify-content:center;
}

.btnRow{display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end}
.btn{
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.04);
  color:var(--text);
  padding:8px 10px;
  border-radius:10px;
  font-size:12px;
  cursor:pointer;
}
.btn:focus{
  outline:2px solid rgba(111,177,255,.55);
  outline-offset:2px;
}
.btn:focus-visible{
  outline:2px solid rgba(111,177,255,.70);
  outline-offset:2px;
}

select.btn{
  background:rgba(13,20,38,.92);
  border-color:rgba(255,255,255,.18);
  min-width:260px;
}
select.btn:hover{
  border-color:rgba(111,177,255,.55);
}
select.btn option{
  background:rgba(13,20,38,1);
  color:var(--text);
}
.btn:active{transform:translateY(1px)}

canvas{
  width: 1100px;
  height: 620px;
  max-width: 100%;
  display:block;
  border:2px solid rgba(255,255,255,.80);
  border-radius:16px;
  background:linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.01));
}

.kv{display:flex;justify-content:space-between;gap:12px;padding:10px 12px;border:1px solid rgba(255,255,255,.08);border-radius:14px;background:rgba(13,20,38,.35)}
.k{color:var(--muted);font-size:12px}
.v{font-weight:900;font-size:12px;white-space:nowrap}

.kvBig .k{font-size:14px}
.kvBig .v{font-size:22px}

.group{margin-top:10px}
.groupTitle{font-size:12px;font-weight:900;letter-spacing:.2px;color:rgba(234,240,255,.86);margin-bottom:8px}
.help{margin-top:6px;color:var(--muted);font-size:12px;line-height:1.35}

.legend{display:flex;flex-direction:column;gap:8px}
.legRow{display:flex;align-items:center;justify-content:space-between;gap:12px;border:1px solid rgba(255,255,255,.08);border-radius:14px;background:rgba(13,20,38,.25);padding:8px 10px}
.swatch{width:14px;height:14px;border-radius:5px;border:1px solid rgba(255,255,255,.20)}
.legLeft{display:flex;align-items:center;gap:10px}
.legName{font-size:12px;font-weight:900}
.legHint{font-size:12px;color:var(--muted)}

.aiCard{margin-bottom:12px;}

.aiRow{
  display:grid;
  grid-template-columns:56px 1fr;
  gap:12px;
  align-items:start;
}

.aiAvatarWrap{
  width:56px;
  height:56px;
  position:relative;
}

.aiAvatar{
  width:56px;
  height:56px;
  border-radius:999px;
  --mouth-center: 0%;
  background:
    radial-gradient(circle at 35% 35%, rgba(255,255,255,0.50), transparent 45%),
    radial-gradient(circle at 50% 70%, rgba(0,0,0,0.18), transparent 55%),
    linear-gradient(180deg, #ffd2a6, #f1b98d);
  position:relative;
  overflow:hidden;
  box-shadow: inset 0 3px 10px rgba(255,255,255,0.14), inset 0 -10px 16px rgba(0,0,0,0.22), 0 14px 22px rgba(0,0,0,0.30);
}

.aiAvatar.sad{
  --mouth-center: 100%;
}

.aiArrow{
  position:absolute;
  top:-16px;
  right:-16px;
  width:34px;
  height:34px;
  display:grid;
  place-items:center;
  border-radius:999px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.18);
  box-shadow: 0 10px 16px rgba(0,0,0,0.28);
  z-index:5;
  color:#ffffff;
  font-size:16px;
  font-weight:1000;
  letter-spacing:-0.4px;
  opacity:0;
  transform: translateY(2px) scale(0.98);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events:none;
}

.aiAvatar.happy + .aiArrow,
.aiAvatar.sad + .aiArrow{
  opacity:1;
  transform: translateY(0) scale(1);
}

.aiAvatar::before{
  content:"";
  position:absolute;
  inset:-2px -2px 18px -2px;
  border-radius:999px;
  background:
    radial-gradient(circle at 50% 15%, rgba(255,255,255,0.10), transparent 60%),
    linear-gradient(180deg, #2a2a2a, #101010);
  clip-path: ellipse(65% 55% at 50% 25%);
  opacity:0.95;
}

.aiAvatar::after{
  content:"";
  position:absolute;
  inset:0;
  border-radius:999px;
  background:
    radial-gradient(circle at 38% 52%, #ffffff 0 1.0px, transparent 1.25px),
    radial-gradient(circle at 62% 52%, #ffffff 0 1.0px, transparent 1.25px),
    radial-gradient(circle at 38% 52%, rgba(0,0,0,0.85) 0 2.6px, transparent 3px),
    radial-gradient(circle at 62% 52%, rgba(0,0,0,0.85) 0 2.6px, transparent 3px),
    radial-gradient(circle at 50% var(--mouth-center), transparent 0 10px, rgba(0,0,0,0.62) 10px 12px, transparent 12.8px);
  background-repeat: no-repeat;
  background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 34px 18px;
  background-position: 0 0, 0 0, 0 0, 0 0, 50% 90%;
  opacity:0.85;
}

.aiDialog{
  margin-top:8px;
  padding:10px 12px;
  border:1px solid rgba(255,255,255,.14);
  border-radius:12px;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  color:var(--muted);
  font-size:14px;
  font-weight:800;
  line-height:1.35;
  min-height:44px;
}




.mapWrap{
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.18);
  overflow:hidden;
  padding: 12px;
}

.mapSerp{
  padding: 16px;
  height: min(72vh, 640px);
}

.mapPath{
  position:absolute;
  inset: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  pointer-events:none;
}

.mapPath path{
  fill:none;
  stroke: rgba(255,255,255,0.18);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mapNodes{
  position:absolute;
  inset: 16px;
}

.mapNode{
  width: 84px;
  height: 84px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.16);
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,0.45), transparent 40%),
    linear-gradient(180deg, rgba(255,255,255,0.10), rgba(0,0,0,0.18));
  box-shadow: 0 16px 28px rgba(0,0,0,0.35);
  display:grid;
  place-items:center;
  cursor:pointer;
  user-select:none;
  transition: transform 160ms ease, filter 160ms ease, border-color 160ms ease, opacity 160ms ease;
  position:absolute;
  transform: translate(-50%, -50%);
}

.mapNode:hover{filter:brightness(1.06); transform: translateY(-1px) scale(1.02)}

.mapNode .n{
  font-weight: 1000;
  font-size: 26px;
  color: rgba(255,255,255,0.92);
}

.mapNode.locked{
  opacity: 0.45;
  cursor:not-allowed;
  filter: grayscale(0.45);
}

.mapNode.unlocked{
  border-color: rgba(255, 209, 102, 0.75) !important;
  box-shadow:
    0 16px 28px rgba(0,0,0,0.35),
    0 0 24px rgba(255, 209, 102, 0.18);
}

.mapNode.cleared{
  background: linear-gradient(180deg, rgba(255, 209, 102, 0.28), rgba(0,0,0,0.18));
  border-color: rgba(255, 209, 102, 0.65);
}

.mapNode.selected{
  border-color: rgba(45, 212, 191, 0.65);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.14), 0 18px 28px rgba(0,0,0,0.30);
}

@media (prefers-reduced-motion: reduce){
  *{scroll-behavior:auto}
}
