:root {
    --bg: #1f2023;
    --dot: #4a4c50;
    --fg: #d8d8d8;
    --muted: #8a8d92;
    --accent: #98c379;
    --panel: #26282c;
    --border: #34373c;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: 'JetBrains Mono', 'DejaVu Sans Mono', ui-monospace, monospace;
}

/* ---------- login ---------- */

.login-wrap {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 340px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 22px;
    color: var(--accent);
}

.login-card .sub {
    margin: 0 0 20px;
    color: var(--muted);
    font-size: 13px;
}

.panel {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    margin-top: 16px;
}

.panel:first-of-type {
    border-top: 0;
    padding-top: 0;
    margin-top: 0;
}

.panel h2 {
    margin: 0 0 10px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

input {
    width: 100%;
    padding: 9px 10px;
    margin-bottom: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--fg);
    font: inherit;
    font-size: 14px;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    width: 100%;
    padding: 9px 10px;
    background: var(--accent);
    color: #14231a;
    border: 0;
    border-radius: 6px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

button.ghost {
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--border);
}

button:hover {
    filter: brightness(1.08);
}

.error {
    color: #e06c75;
    font-size: 13px;
    min-height: 18px;
    margin-top: 6px;
}

.row {
    display: flex;
    gap: 8px;
}

.row input {
    margin-bottom: 0;
}

/* ---------- room ---------- */

body.room {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#room {
    position: relative;
    background-color: var(--bg);
    background-image: radial-gradient(circle, var(--dot) 1.4px, transparent 1.8px);
    background-size: var(--cell) var(--cell);
    background-position: calc(var(--cell) / 2) calc(var(--cell) / 2);
    border: 1px solid var(--border);
    overflow: hidden;
}

.layer {
    position: absolute;
    inset: 0;
}

.word {
    position: absolute;
    top: 0;
    left: 0;
    font-size: calc(var(--cell) * 0.8);
    line-height: var(--cell);
    white-space: pre;
    pointer-events: none;
    will-change: transform;
}

.word.spiral {
    width: 0;
    height: 0;
    overflow: visible;
}

.word.spiral .wc {
    position: absolute;
    width: var(--cell);
    height: var(--cell);
    text-align: center;
    line-height: var(--cell);
}

.word .wc.done {
    opacity: 0.25;
    text-decoration: line-through;
}

.word .wc.next {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 3px;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
}

.player {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--cell);
    height: var(--cell);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.06s linear;
    pointer-events: none;
}

.player .glyph {
    font-size: calc(var(--cell) * 0.9);
    line-height: 1;
    font-weight: 700;
}

.player .label {
    position: absolute;
    top: calc(var(--cell) * 0.92);
    font-size: calc(var(--cell) * 0.34);
    color: var(--muted);
    white-space: nowrap;
}

.player .saying {
    position: absolute;
    left: calc(var(--cell) * 0.95);
    top: 0;
    height: var(--cell);
    display: flex;
    align-items: center;
    font-size: calc(var(--cell) * 0.72);
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
}

.player.you .glyph {
    color: #ffffff !important;
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.35);
}

.player.pending {
    opacity: 0.45;
}

#hud {
    position: fixed;
    top: 10px;
    left: 12px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    gap: 12px;
    align-items: center;
}

#hud .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e06c75;
    display: inline-block;
}

#hud.online .dot {
    background: var(--accent);
}

#guestbar {
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    gap: 8px;
    align-items: center;
}

#guestbar span {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

#guestbar input {
    width: 130px;
    margin: 0;
}

#guestbar button {
    width: auto;
    padding: 8px 12px;
}

#guestbar .error {
    margin: 0;
}

.hidden {
    display: none !important;
}

/* ---------- D-pad ---------- */

#dpad {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 10;
    touch-action: none;
}

@media (hover: none) and (pointer: coarse) {
    #dpad { display: flex; }
}

.dpad-mid {
    display: flex;
    gap: 4px;
    align-items: center;
}

.dpad-center {
    width: 44px;
    height: 44px;
}

#dpad button {
    width: 52px;
    height: 52px;
    padding: 0;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    color: var(--fg);
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

#dpad button:active {
    background: rgba(255, 255, 255, 0.15);
}

/* ---------- write mode ---------- */

#write-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 15;
}

body.write-mode #write-backdrop {
    display: block;
}

#write-input {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    width: min(300px, 85vw);
    margin: 0;
    display: none;
    z-index: 20;
    background: var(--panel);
    border-color: var(--accent);
    font-size: 16px;
}

#write-input.active {
    display: block;
}

#write-btn {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: auto;
    padding: 0 20px;
    height: 52px;
    z-index: 20;
    font-size: 14px;
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    #write-btn { display: flex; align-items: center; justify-content: center; }
}
