:root { --ink: #eef0fa; --dim: rgba(238, 240, 250, 0.62); --glass: rgba(16, 20, 40, 0.72); --line: rgba(255, 255, 255, 0.12);
  --gold: #ffcf6a; --warm: #ff9a4a; --ok: #6dffb0; --bad: #ff8a8a; --cyan: #7ae8ff; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #05060c; color: var(--ink); font: 14px/1.45 Inter, system-ui, sans-serif; user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: none; }
button:disabled { cursor: default; opacity: 0.4; }
.primary { background: linear-gradient(180deg, #ffd67a, #ff9a4a); color: #2a1604; border-radius: 14px; padding: 9px 16px; font: 800 16px 'Baloo 2', sans-serif;
  box-shadow: 0 6px 22px rgba(255, 170, 80, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.5); }
.primary:hover:not(:disabled) { filter: brightness(1.07); }
.primary.big { font-size: 20px; padding: 11px 22px; }
.ghost { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; }
.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
.ghost.icon { padding: 6px 10px; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; padding: 16px; }
#title { background: radial-gradient(ellipse at center, rgba(5, 6, 12, 0) 30%, rgba(5, 6, 12, 0.75)); }
.logo { text-align: center; }
.logo h1 { margin: 0; font: 800 clamp(56px, 11vw, 120px)/0.9 'Baloo 2', sans-serif; letter-spacing: -0.02em;
  text-shadow: 0 0 40px rgba(255, 190, 90, 0.35); }
.logo h1 span { background: linear-gradient(180deg, #fff3c4, #ffcf6a 50%, #ff8a3d); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo p { color: var(--dim); font-size: 17px; margin: 10px 0 22px; }
.logo .small { font-size: 13px; margin-top: 18px; }

#select { background: rgba(5, 6, 12, 0.55); backdrop-filter: blur(6px); }
.selbox { width: min(980px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--glass); border: 1px solid var(--line);
  border-radius: 22px; padding: 18px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.selhead { display: flex; align-items: center; gap: 14px; }
.selhead h2 { flex: 1; margin: 0; font: 800 28px 'Baloo 2', sans-serif; }
.startotal { color: var(--gold); font: 700 18px 'Baloo 2', sans-serif; }
.world h3 { margin: 16px 0 2px; font: 800 20px 'Baloo 2', sans-serif; }
.world h3 span { color: var(--gold); font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; margin-right: 6px; }
.world p { margin: 0 0 8px; color: var(--dim); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tile { text-align: left; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 2px; transition: transform 0.12s, background 0.12s; }
.tile:hover:not(:disabled) { transform: translateY(-2px); background: rgba(255, 207, 106, 0.12); border-color: rgba(255, 207, 106, 0.5); }
.tile .num { font: 700 12px 'Baloo 2', sans-serif; color: var(--gold); letter-spacing: 0.08em; }
.tile .nm { font-weight: 600; }
.tile .st i { font-style: normal; color: rgba(255, 255, 255, 0.2); }
.tile .st i.on { color: var(--gold); text-shadow: 0 0 8px rgba(255, 207, 106, 0.8); }
.tile.locked { opacity: 0.4; }

.topbar { position: fixed; top: 12px; left: 12px; display: flex; gap: 12px; align-items: center; z-index: 3; }
.topbar .ghost.icon { margin-left: 4px; }
.lvlid { color: var(--gold); font: 700 12px 'Baloo 2', sans-serif; letter-spacing: 0.14em; text-transform: uppercase; }
.lvlname { font: 800 26px/1 'Baloo 2', sans-serif; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); }

.panel { position: fixed; top: 12px; right: 12px; bottom: 12px; width: 320px; overflow: auto; background: var(--glass); border: 1px solid var(--line);
  border-radius: 20px; padding: 16px 16px 12px; backdrop-filter: blur(12px); box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45); z-index: 3; }
.panel h4 { margin: 12px 0 6px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); display: flex; gap: 8px; align-items: center; }
.panel h4 em { font-style: italic; text-transform: none; font-size: 14px; color: var(--ink); }
.story { margin: 0; color: var(--ink); font-size: 14.5px; }
.goal { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; background: rgba(255, 255, 255, 0.03); transition: border-color 0.2s, background 0.2s; }
.goal.ok { border-color: rgba(109, 255, 176, 0.5); background: rgba(109, 255, 176, 0.06); }
.goal.bad { border-color: rgba(255, 138, 138, 0.35); }
.gh { display: flex; align-items: center; gap: 8px; }
.gh b { flex: 1; }
.gh em { font-style: normal; font-weight: 800; }
.goal.ok .gh em { color: var(--ok); } .goal.bad .gh em { color: var(--bad); }
.gd { color: var(--dim); font-size: 12.5px; margin: 2px 0 6px; }
.ico { width: 16px; height: 16px; border-radius: 4px; display: inline-block; background: #888; }
.ico.village { background: linear-gradient(135deg, #e8d3ae, #b3473a); } .ico.farm { background: linear-gradient(135deg, #ffe07a, #7fbf4a); }
.ico.cave { background: radial-gradient(circle at 50% 70%, #0c0a0c 40%, #5a4a3f 42%); } .ico.tower { background: linear-gradient(180deg, #ffb24a, #9a8e80 40%); }
.ico.temple { background: repeating-linear-gradient(90deg, #d8d2c4 0 3px, #6a665e 3px 5px); }
.meter { position: relative; height: 18px; border-radius: 9px; background: rgba(0, 0, 0, 0.35); overflow: hidden; }
.meter .fill { position: absolute; inset: 0 auto 0 0; border-radius: 9px; transition: width 0.15s; }
.meter.light .fill { background: linear-gradient(90deg, #7a5a2a, #ffcf6a); box-shadow: 0 0 10px rgba(255, 207, 106, 0.5); }
.meter.dark .fill { background: linear-gradient(90deg, #3b3a6a, #ff8a6a); }
.meter .line { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; box-shadow: 0 0 6px #fff; }
.meter span { position: absolute; right: 8px; top: 0; font: 600 11px/18px Inter, sans-serif; text-shadow: 0 1px 2px #000; }
.linkstate { font-weight: 600; color: var(--bad); } .linkstate.ok { color: var(--cyan); text-shadow: 0 0 10px rgba(122, 232, 255, 0.6); }
.chips { display: flex; gap: 4px; margin-top: 6px; }
.chips span { font-size: 11px; padding: 1px 7px; border-radius: 8px; background: rgba(255, 138, 138, 0.15); color: var(--bad); }
.chips span.ok { background: rgba(109, 255, 176, 0.15); color: var(--ok); }
.seg { display: flex; gap: 3px; background: rgba(0, 0, 0, 0.3); padding: 3px; border-radius: 12px; }
.seg button { flex: 1; background: transparent; border-radius: 9px; padding: 6px 0; font-weight: 600; }
.seg button.on { background: var(--gold); color: #2a1604; box-shadow: 0 0 12px rgba(255, 207, 106, 0.5); }
.lock { font-size: 11px; letter-spacing: 0; text-transform: none; color: var(--dim); }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--dim); }
.actions { margin-top: 14px; display: grid; gap: 8px; }
.actions .row { display: flex; gap: 8px; } .actions .row button { flex: 1; }
.par { text-align: center; color: var(--gold); font-size: 12.5px; margin: 0; }

.tray { position: fixed; left: calc((100vw - 340px) / 2 + 20px); transform: translateX(-50%); bottom: 34px; display: flex; gap: 10px; z-index: 3; }
.tcard { display: flex; align-items: center; gap: 8px; background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 6px 14px 6px 6px;
  cursor: grab; backdrop-filter: blur(10px); box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4); touch-action: none; transition: transform 0.12s, border-color 0.12s; }
.tcard:hover { transform: translateY(-3px); border-color: rgba(255, 207, 106, 0.6); }
.tcard b { display: block; font: 700 15px 'Baloo 2', sans-serif; }
.tcard .left { color: var(--gold); font-weight: 600; }
.tnone { color: var(--dim); background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 10px 16px; }
.helpline { position: fixed; bottom: 10px; left: calc((100vw - 340px) / 2 + 20px); transform: translateX(-50%); font-size: 12px; color: var(--dim); white-space: nowrap; z-index: 3; }
.toast { position: fixed; top: 20px; left: calc((100vw - 340px) / 2 + 20px); transform: translateX(-50%); background: rgba(40, 10, 16, 0.85); border: 1px solid rgba(255, 138, 138, 0.5);
  padding: 8px 16px; border-radius: 12px; opacity: 0; transition: opacity 0.3s; z-index: 4; font-weight: 600; pointer-events: none; }
.toast.on { opacity: 1; }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

#win { background: rgba(5, 6, 12, 0.5); backdrop-filter: blur(4px); }
.winbox { background: var(--glass); border: 1px solid rgba(255, 207, 106, 0.4); border-radius: 24px; padding: 24px 30px; text-align: center; width: min(420px, 100%);
  box-shadow: 0 0 80px rgba(255, 190, 90, 0.25), 0 20px 60px rgba(0, 0, 0, 0.5); animation: rise 0.4s ease-out; }
.wtitle { font: 800 40px/1 'Baloo 2', sans-serif; background: linear-gradient(180deg, #fff3c4, #ffcf6a 55%, #ff8a3d); -webkit-background-clip: text; background-clip: text; color: transparent; }
.wstars { font-size: 54px; margin: 8px 0 2px; }
.wstars i { font-style: normal; color: rgba(255, 255, 255, 0.15); display: inline-block; }
.wstars i.on { color: var(--gold); text-shadow: 0 0 20px rgba(255, 207, 106, 0.9); animation: pop 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) backwards; }
.winbox p { color: var(--dim); margin: 0 0 14px; }
.wbtns { display: grid; gap: 8px; }
.wbtns button:not(.primary) { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
@keyframes pop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 900px) {
  .panel { top: auto; left: 8px; right: 8px; width: auto; height: 36vh; bottom: 88px; }
  .tray { left: 50%; bottom: 30px; } .helpline { display: none; } .toast { left: 50%; }
}
