:root {
    --bg: #0f1013;
    --bg-elev: #17181c;
    --bg-surf: #1c1d22;
    --bg-hi:   #262830;
    --border: #2a2c33;
    --text: #e8e9eb;
    --dim:  #9aa0a6;
    --faint: #6a6c70;
    --accent: #7a5cff;
    --accent-2: #5b3fe6;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad:  #f87171;
    --info: #60a5fa;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
    height: 100%;
    width: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter","SF Pro Text","Segoe UI",sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

button { font-family: inherit; color: inherit; }

.hidden { display: none !important; }

#app {
    display: grid;
    grid-template-columns: 38% 62%;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    gap: 8px;
    padding: 8px;
}

/* ----- LEFT (status + mons) ----- */
.left {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}
.status {
    flex-shrink: 0;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-align: center;
}
.status-connected { background: rgba(74,222,128,.18); color: var(--good); }
.status-waiting   { background: rgba(251,191,36,.18); color: var(--warn); }
.status-offline   { background: rgba(248,113,113,.18); color: var(--bad); }

.mons {
    flex: 1;
    display: grid;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 6px;
    min-height: 0;
}
.mon-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 8px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.mon-card.dim { opacity: .35; }
.mon-tag {
    font-size: 9px;
    letter-spacing: .8px;
    color: var(--faint);
    font-weight: 700;
    margin-bottom: 2px;
}
.mon-with-sprite {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
    min-height: 0;
}
.mon-sprite {
    width: 56px;
    height: 56px;
    object-fit: contain;
    image-rendering: pixelated;
    flex-shrink: 0;
}
.mon-body { flex: 1; min-width: 0; }
.mon-species {
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mon-line {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--dim);
    margin-top: 2px;
}
.hp-bar {
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
}
.hp-fill { height: 100%; background: var(--good); transition: width .25s; }
.hp-fill.med { background: var(--warn); }
.hp-fill.low { background: var(--bad); }

.badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    background: var(--warn);
    color: #000;
    margin-left: 4px;
    vertical-align: middle;
}
.dash { color: var(--faint); font-size: 13px; }

/* ----- RIGHT (action panel) ----- */
.right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}
.tabs {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}
.tab {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 4px;
    color: var(--dim);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-height: 38px;
}
.tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.tab:disabled { opacity: 0; pointer-events: none; }

.pane {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.idle-pane { align-items: center; justify-content: center; }
.idle-text {
    color: var(--faint);
    font-size: 16px;
    text-align: center;
    padding: 20px;
}

/* ----- Move grid (2x2 fill) ----- */
.grid-2x2 {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    min-height: 0;
}
.move-btn {
    background: var(--bg-surf);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 0;
    transition: transform .08s, background .15s, border-color .15s;
}
.move-btn:active:not(:disabled) { transform: scale(.97); }
.move-btn.selected {
    border-color: var(--accent);
    background: rgba(122,92,255,.18);
}
.move-btn:disabled { opacity: .35; cursor: not-allowed; }
.move-name {
    font-weight: 700;
    font-size: 18px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.move-pp {
    font-size: 12px;
    color: var(--dim);
    margin-top: 2px;
}

.move-btn.action-fight {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: var(--accent);
    color: #fff;
}
.move-btn.action-fight .move-name { font-size: 32px; letter-spacing: 2px; }
.move-btn.action-fight .move-pp { color: rgba(255,255,255,.8); font-size: 14px; }

/* ----- Target picker ----- */
.target-picker {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    height: 64px;
}
.target-btn {
    background: var(--bg-surf);
    border: 2px solid var(--accent);
    border-radius: 10px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform .08s, background .15s;
}
.target-btn:active { transform: scale(.97); background: rgba(122,92,255,.25); }
.target-arrow { font-size: 22px; color: var(--accent); }
.target-label { font-weight: 800; font-size: 14px; letter-spacing: 1px; }
.target-sub { font-size: 11px; color: var(--faint); }

/* ----- Switch / Item grid (2x3 fill) ----- */
.grid-2x3 {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 6px;
    min-height: 0;
}
.party-row, .item-btn {
    background: var(--bg-surf);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 6px 8px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 0;
    overflow: hidden;
    gap: 2px;
    transition: transform .08s, border-color .15s;
}
.party-row:active:not(.disabled), .item-btn:active { transform: scale(.97); }
.party-row.disabled { opacity: .3; cursor: not-allowed; }
.party-sprite {
    width: 48px;
    height: 48px;
    object-fit: contain;
    image-rendering: pixelated;
    flex-shrink: 0;
}
.party-row .mon-species, .item-btn .mon-species { font-size: 12px; }
.party-row .mon-line, .item-btn .mon-line {
    width: 100%;
    font-size: 10px;
}
.party-row .hp-bar { width: 80%; }

/* ----- Cancel pane ----- */
.cancel-pane { align-items: center; justify-content: center; gap: 16px; }
.cancel-text { font-size: 17px; color: var(--dim); }
.big-btn {
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 1px;
    padding: 14px 36px;
    cursor: pointer;
    min-height: 56px;
}
.big-btn:active { transform: scale(.97); }

/* ----- Portrait warning ----- */
@media (orientation: portrait) {
    #app::before {
        content: "⟲ rotate to landscape";
        position: fixed;
        inset: 0;
        background: var(--bg);
        color: var(--dim);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        z-index: 100;
        letter-spacing: 1px;
    }
}

/* very small viewport tightening */
@media (max-height: 380px) {
    .mon-sprite { width: 44px; height: 44px; }
    .move-name { font-size: 15px; }
    .tab { font-size: 11px; min-height: 32px; padding: 6px 2px; }
}
