:root {
    --bg: #0c1018;
    --glass: rgba(18, 23, 34, 0.9);
    --line: rgba(255, 255, 255, 0.1);
    --text: #ffffff;
    --dim: #9aa6bd;
    --accent: #4c8dff;
    --star: #ffd34d;
    --shade: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.55);
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--text);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    background: radial-gradient(120% 90% at 50% 35%, #1a2233 0%, var(--bg) 70%);
    user-select: none;
    -webkit-user-select: none;
}

#map {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    cursor: default;
    touch-action: none;
}

button {
    font: inherit;
    color: inherit;
    border: 0;
    background: none;
    cursor: pointer;
    padding: 0;
    touch-action: manipulation;
}

i.star {
    display: inline-block;
    width: 0.95em;
    height: 0.95em;
    margin: 0 0.18em 0 0;
    vertical-align: -0.1em;
    background: url(/textures/misc/resource.png) center / contain no-repeat;
}

.cost i.star, small i.star { margin: 0 0 0 0.1em; }

/* top: score, stars, turn, as in the game */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 110px;
    padding-top: max(14px, env(safe-area-inset-top));
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: linear-gradient(rgba(8, 13, 30, 0.82), rgba(8, 13, 30, 0));
    pointer-events: none;
    text-shadow: var(--shade);
}

#stats { display: flex; }

.stat {
    padding: 0 26px;
    text-align: center;
    min-width: 112px;
}

.stat + .stat { border-left: 1px solid rgba(255, 255, 255, 0.4); }
.stat span { display: block; font-size: 13px; font-weight: 500; opacity: 0.9; white-space: nowrap; }
.stat b { display: block; font-size: 27px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.stat b small { font-size: 14px; font-weight: 600; opacity: 0.8; }
.stat .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.5); }
.stat .dot.on { box-shadow: 0 0 0 2px #fff; }

#foe { position: absolute; left: 16px; top: 14px; }

.foe {
    display: flex;
    align-items: center;
    gap: 9px;
    opacity: 0.85;
}

.foe.active { opacity: 1; }
.foe img { width: 38px; height: 38px; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7)); }
.foe span { display: block; font-size: 12px; font-weight: 500; opacity: 0.9; }
.foe b { display: block; font-size: 16px; font-weight: 700; }
.foe .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.5); }
.foe b small { font-size: 12px; opacity: 0.8; }

/* bottom: round buttons, as in the game */
#dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 46px 12px max(12px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: linear-gradient(rgba(8, 13, 30, 0), rgba(8, 13, 30, 0.86));
    pointer-events: none;
    text-shadow: var(--shade);
}

#info {
    padding: 8px 18px;
    border-radius: 14px;
    background: rgba(10, 16, 36, 0.8);
    text-align: center;
    text-shadow: none;
}

#info[hidden] { display: none; }
#info b { display: block; font-size: 16px; font-weight: 700; }
#info span { display: block; font-size: 12.5px; color: #c9d3e6; margin-top: 1px; }

#bar {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
    pointer-events: auto;
}

.rb {
    width: 84px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.15;
    text-align: center;
    text-shadow: var(--shade);
}

.rb .disc {
    width: 62px;
    height: 62px;
    display: grid;
    place-items: center;
    background: url(/textures/misc/bgAvailable.png) center / contain no-repeat;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.5));
    transition: transform 0.08s;
}

@media (hover: hover) { .rb:hover .disc { transform: scale(1.07); } }
.rb:active .disc { transform: scale(0.96); }
.rb .disc svg { width: 28px; height: 28px; fill: none; stroke: #fff; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.rb .disc svg.fill { fill: #fff; stroke: none; }
.rb .pic { width: 42px; height: 42px; background: center / contain no-repeat; }
.rb .pic.zoom { width: 56px; height: 56px; background-size: 185%; background-position: 50% 46%; border-radius: 50%; }
.rb.green .disc { background-image: url(/textures/misc/bgComplete.png); }
.rb.off { opacity: 0.45; pointer-events: none; }
.rb .cost { color: var(--star); font-weight: 700; }
.rb.speed { width: 170px; padding-top: 22px; gap: 22px; }
#speed { width: 150px; accent-color: #39a0ff; pointer-events: auto; }

/* overlays */
#overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(6, 9, 15, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

#overlay[hidden] { display: none !important; }
#overlay.clear { background: none; backdrop-filter: none; -webkit-backdrop-filter: none; pointer-events: none; place-items: end center; padding-bottom: 150px; }
#overlay.clear .card { pointer-events: auto; }
#overlay.full { display: block; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }

.card {
    background: var(--glass);
    border: 1px solid var(--line);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 22px;
    padding: 26px 28px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    overflow: auto;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.card h1 { margin: 0 0 4px; font-size: 21px; font-weight: 680; letter-spacing: -0.01em; }
.card .lead { margin: 0 0 18px; font-size: 13px; color: var(--dim); }
.card h2 { margin: 18px 0 8px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }

.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); gap: 2px; flex-wrap: wrap; }
.seg button { padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--dim); }
.seg button.on { background: rgba(255, 255, 255, 0.14); color: var(--text); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.tribes { display: grid; grid-template-columns: repeat(4, 74px); gap: 6px; }

.tribe {
    height: 74px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 5px;
    font-size: 11px;
    font-weight: 600;
    color: var(--dim);
    background: rgba(255, 255, 255, 0.045) center 7px / 44px no-repeat;
    border: 1.5px solid transparent;
}

@media (hover: hover) { .tribe:hover { background-color: rgba(255, 255, 255, 0.1); } }
.tribe.on { border-color: var(--c, #fff); color: var(--text); background-color: rgba(255, 255, 255, 0.1); }
.row { display: flex; column-gap: 22px; row-gap: 0; flex-wrap: wrap; }

.primary {
    margin-top: 22px;
    height: 46px;
    width: 100%;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 650;
}

@media (hover: hover) {
    .primary:hover { filter: brightness(1.1); }
    .ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
    .choice:hover { background: rgba(255, 255, 255, 0.13); border-color: var(--line); }
    .mode:hover { background: rgba(255, 255, 255, 0.12); }
    .tnode:hover { transform: scale(1.08); z-index: 2; }
}
.ghost { margin-top: 8px; height: 40px; width: 100%; border-radius: 12px; color: var(--dim); font-size: 13.5px; font-weight: 600; }

/* menu pages: start, skill, setup; the notice sits at the bottom */
#overlay.pages { display: block; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: max(20px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
}
.page .card { margin: auto 0; max-height: none; overflow: visible; }
.notice {
    max-width: 560px;
    margin: 18px 0 0;
    font-size: 11.5px;
    line-height: 1.45;
    text-align: center;
    color: #7f8aa3;
}

.card.start { width: 420px; }
.modes { display: flex; flex-direction: column; gap: 10px; }
.mode {
    padding: 16px 18px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--line);
    text-align: left;
}
.mode b { display: block; font-size: 16px; }
.mode span { display: block; margin-top: 3px; font-size: 13px; color: var(--dim); }
.cardtop { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
.cardtop h1 { margin: 0; }
.back { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.08); flex: none; }
.back svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* reward choice */
.choices { display: flex; gap: 10px; }
.choice { width: 170px; padding: 16px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); text-align: left; border: 1px solid transparent; }
.choice b { display: block; font-size: 14.5px; margin-bottom: 4px; }
.choice span { font-size: 12.5px; color: var(--dim); line-height: 1.35; }

/* tech tree: a wheel around the tribe, as in the game */
.tech {
    position: absolute;
    inset: 0;
    background: radial-gradient(90% 80% at 50% 50%, #24407e 0%, #152650 55%, #0d1834 100%);
    overflow: hidden;
}

.tech h1 { margin: 18px 0 2px; text-align: center; font-size: 22px; font-weight: 700; }
.tech .hint { margin: 0 64px; text-align: center; font-size: 13px; color: #c9d6f2; }

.tclose {
    position: absolute;
    top: 16px;
    right: 18px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.12);
}

.tclose:hover { background: rgba(255, 255, 255, 0.22); }
.tclose svg { width: 20px; height: 20px; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; fill: none; }

.tree {
    position: absolute;
    left: 50%;
    top: calc(50% + 14px);
    width: 0;
    height: 0;
    transform: scale(var(--k, 1));
}

.tlines { position: absolute; left: -540px; top: -540px; width: 1080px; height: 1080px; pointer-events: none; }
.tlines line { stroke: rgba(255, 255, 255, 0.28); stroke-width: 5; stroke-linecap: round; }
.tlines line.on { stroke: #6fe07a; }

.thub {
    position: absolute;
    left: -52px;
    top: -52px;
    width: 104px;
    height: 104px;
    border-radius: 50%;
    background: #0f1c3f center / 74% no-repeat;
    box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.85);
}

.tnode {
    position: absolute;
    width: 86px;
    height: 86px;
    margin: -43px 0 0 -43px;
    display: grid;
    place-items: center;
    background: url(/textures/misc/bgUnavailable.png) center / contain no-repeat;
    transition: transform 0.08s;
}

.tnode.open { background-image: url(/textures/misc/bgAvailable.png); }
.tnode.done { background-image: url(/textures/misc/bgComplete.png); }
.tnode.dear { background-image: url(/textures/misc/bgExpensive.png); }
.tnode.sel { filter: drop-shadow(0 0 10px #fff); }
.tnode .pic { width: 54px; height: 54px; background: center / contain no-repeat; }
.tnode .pic.zoom { width: 76px; height: 76px; background-size: 185%; background-position: 50% 46%; border-radius: 50%; }
.tnode.locked .pic { opacity: 0.38; filter: grayscale(0.9); }

.tname {
    position: absolute;
    top: 88px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 15px;
    font-weight: 650;
    text-align: center;
    text-shadow: var(--shade);
    line-height: 1.15;
}

.tname small { display: block; font-size: 14px; font-weight: 700; color: var(--star); }
.tnode.locked .tname { color: #a9b6d6; }
.tnode.locked .tname small { opacity: 0.7; }

.tcard {
    position: absolute;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 14px 16px 14px 22px;
    border-radius: 18px;
    background: rgba(8, 14, 34, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.tcard b { display: block; font-size: 17px; }
.tcard span { display: block; font-size: 13px; color: #c9d6f2; margin-top: 2px; min-height: 16px; }
.tcard button { height: 44px; padding: 0 22px; border-radius: 22px; font-size: 14.5px; font-weight: 700; }
.tcard button.go { background: #37b24d; color: #fff; }
.tcard button.go:hover { filter: brightness(1.12); }
.tcard button.no { background: rgba(255, 255, 255, 0.1); color: #c9d6f2; cursor: default; }

/* tech tree on phones: one row per branch */
.tlist {
    position: absolute;
    top: 84px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 10px 150px;
}
.tbranch {
    display: grid;
    grid-template-columns: 1fr 2fr;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.tbranch .troot { grid-row: span 2; }
.trow { display: grid; grid-template-columns: 1fr 1fr; }
.tlist .tnode {
    position: relative;
    width: 100%;
    height: auto;
    margin: 0;
    padding: 4px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
}
.tlist .tnode::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 50%;
    width: 58px;
    height: 58px;
    margin-left: -29px;
    background: url(/textures/misc/bgUnavailable.png) center / contain no-repeat;
}
.tlist .tnode.open::before { background-image: url(/textures/misc/bgAvailable.png); }
.tlist .tnode.done::before { background-image: url(/textures/misc/bgComplete.png); }
.tlist .tnode.dear::before { background-image: url(/textures/misc/bgExpensive.png); }
.tlist .tnode .pic { position: relative; width: 58px; height: 58px; background-size: 64%; background-position: center; }
.tlist .tnode .pic.zoom { background-size: 150%; background-position: 50% 46%; border-radius: 50%; }
.tlist .tname { position: static; transform: none; margin-top: 3px; font-size: 12px; white-space: normal; max-width: 100%; }
.tlist .tname small { font-size: 11.5px; }

/* narrow windows */
@media (max-width: 760px) {
    .card { padding: 20px 18px; border-radius: 18px; }
    .cols { grid-template-columns: 1fr; gap: 0; }
    .tribes { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); }
    .tribe { height: 66px; background-size: 38px; font-size: 10.5px; }
    .choices { flex-direction: column; }
    .choice { width: 100%; }
    .stat { padding: 0 14px; min-width: 0; }
    .stat b { font-size: 22px; }
    .stat span { font-size: 12px; }
    #foe { top: 74px; left: 12px; }
    .rb { width: 70px; font-size: 11.5px; flex: none; }
    .rb .disc { width: 54px; height: 54px; }
    .rb .pic { width: 36px; height: 36px; }
    .rb .pic.zoom { width: 48px; height: 48px; }
    /* one row that scrolls sideways when a city offers many units */
    #bar { gap: 6px; flex-wrap: nowrap; max-width: 100%; overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
    #bar::-webkit-scrollbar { display: none; }
    #bar > :first-child { margin-left: auto; }
    #bar > :last-child { margin-right: auto; }
    #dock { padding-top: 30px; gap: 8px; }
    #info { max-width: calc(100vw - 24px); padding: 6px 14px; }
    #info b { font-size: 15px; }
    #info span { font-size: 12px; }
    .card h1 { font-size: 19px; }
    .tribes { gap: 5px; }
}

/* phones: six tribes per row so both sides fit on one screen */
@media (max-width: 480px) {
    .card { padding: 18px 14px; }
    .card h2 { margin: 14px 0 6px; }
    .tribes { grid-template-columns: repeat(6, 1fr); gap: 4px; }
    .tribe { height: 54px; background-size: 30px; background-position: center 5px; font-size: 9.5px; padding-bottom: 4px; border-radius: 10px; letter-spacing: -0.01em; }
    .seg button { padding: 7px 11px; }
    .primary { margin-top: 18px; }
    .rb.speed { width: 132px; }
    #speed { width: 122px; }
    .tcard { flex-direction: column; gap: 10px; white-space: normal; text-align: center; width: calc(100vw - 32px); }
}

/* phones held sideways: slimmer bars so the map keeps some height */
@media (max-height: 500px) {
    #hud { height: 74px; padding-top: max(6px, env(safe-area-inset-top)); }
    .stat span { font-size: 11px; }
    .stat b { font-size: 20px; }
    #foe { top: 8px; }
    .foe img { width: 30px; height: 30px; }
    #dock { padding: 18px 12px max(6px, env(safe-area-inset-bottom)); gap: 4px; }
    .rb { width: 64px; font-size: 11px; }
    .rb .disc { width: 46px; height: 46px; }
    .rb .pic { width: 32px; height: 32px; }
    .rb .pic.zoom { width: 42px; height: 42px; }
    .rb .disc svg { width: 22px; height: 22px; }
}

/* the narrowest phones */
@media (max-width: 360px) {
    .rb { width: 62px; font-size: 10.5px; }
    .rb .disc { width: 48px; height: 48px; }
    .rb .pic { width: 32px; height: 32px; }
    .rb .pic.zoom { width: 42px; height: 42px; }
}
