/* ===========================================================================
   NurmiCraft UI
   ---------------------------------------------------------------------------
   Dark "forest glass" panels floating over the live 3D view. One accent
   color (grass green), one font (Outfit), generous radii, restrained motion.
   The 3D canvas always fills the window; everything here is overlay.
   ======================================================================== */

:root {
  --accent: #76c93f;        /* grass */
  --accent-strong: #8fdd55;
  --accent-dark: #4e9a23;
  --sky: #8fc3ea;           /* matches Engine SKY_COLOR */
  --ink: #eef4ea;           /* primary text */
  --ink-muted: #a8b4a3;
  --danger: #e2654f;
  --warn: #e0b14f;
  --glass: rgba(13, 19, 14, 0.78);
  --glass-soft: rgba(13, 19, 14, 0.55);
  --glass-border: rgba(255, 255, 255, 0.09);
  --radius: 16px;
  --radius-small: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #101713;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* --- the 3D view -------------------------------------------------------- */

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

/* --- overlay root --------------------------------------------------------
   #ui ignores the mouse so the game gets it; each screen/overlay opts back
   in with pointer-events: auto. */

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.screen {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  overflow-y: auto;
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(10, 16, 11, 0.25), transparent),
    linear-gradient(rgba(8, 12, 9, 0.42), rgba(8, 12, 9, 0.58));
  backdrop-filter: blur(2px);
  animation: screen-in 240ms ease-out;
}

@keyframes screen-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.center-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
}

/* --- typography ----------------------------------------------------------- */

.logo {
  margin: 0;
  font-size: clamp(2.6rem, 7vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.logo span {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-small { font-size: 2rem; }

.tagline {
  margin: 10px 0 0;
  color: var(--ink-muted);
  font-size: 1.05rem;
}

.muted { color: var(--ink-muted); }
.small { font-size: 0.85rem; }
.error-text {
  min-height: 1.2em;
  margin: 2px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

/* --- cards ----------------------------------------------------------------- */

.card {
  width: min(440px, calc(100vw - 32px));
  padding: 20px 22px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* --- menu layout ---------------------------------------------------------- */

.menu-layout {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 16px 32px;
}

.menu-header { text-align: center; }

.menu-footer {
  display: flex;
  gap: 8px;
  padding-bottom: 8px;
}

.corner-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 1.2rem;
}

/* --- form fields -------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.field-label output { color: var(--accent-strong); }

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

.field-row input { flex: 1; }

input[type="text"], select {
  width: 100%;
  padding: 11px 14px;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-small);
  outline: none;
  transition: border-color 120ms, background 120ms;
}

input[type="text"]:focus, select:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.09);
}

select option { background: #18211a; color: var(--ink); }

input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

/* --- buttons ------------------------------------------------------------ */

.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  padding: 11px 18px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-small);
  background: rgba(255, 255, 255, 0.07);
  cursor: pointer;
  transition: transform 100ms, background 120ms, border-color 120ms;
}

.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  border-color: transparent;
  color: #10210a;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-dark));
}

.btn-danger { color: #ffd9d1; border-color: rgba(226, 101, 79, 0.45); }
.btn-danger:hover { background: rgba(226, 101, 79, 0.18); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }

.btn-wide { width: 100%; }

.btn-icon {
  padding: 8px 11px;
  line-height: 1;
}

.btn-row {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- live worlds list ------------------------------------------------------ */

#worlds-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.world-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}

.world-row:hover {
  background: rgba(118, 201, 63, 0.12);
  border-color: rgba(118, 201, 63, 0.35);
}

.world-name { font-weight: 600; }
.world-meta {
  color: var(--ink-muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

/* --- how to play ----------------------------------------------------------- */

#help-card summary {
  cursor: pointer;
  list-style: none;
}

#help-card summary::before {
  content: "▸ ";
  color: var(--accent);
}

#help-card[open] summary::before { content: "▾ "; }

.keys-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.key {
  justify-self: start;
  padding: 2px 9px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  border-bottom-width: 2px;
  border-radius: 7px;
  white-space: nowrap;
}

/* --- spinner & progress -------------------------------------------------- */

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.spinner-small {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.progress-track {
  width: min(380px, 80vw);
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dark), var(--accent-strong));
  border-radius: 99px;
  transition: width 160ms ease-out;
}

/* --- ready screen -------------------------------------------------------- */

#screen-ready { cursor: pointer; }

.ready-cta {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 600;
  animation: pulse 1.8s ease-in-out infinite;
}

.ready-cta strong { color: var(--accent-strong); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* --- overlays (settings, restore) ------------------------------------------ */

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 8, 6, 0.55);
  animation: screen-in 160ms ease-out;
  z-index: 30;
}

.settings-card { width: min(400px, calc(100vw - 32px)); }

/* --- reconnect banner ------------------------------------------------------ */

.banner {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  pointer-events: auto;
  background: rgba(64, 48, 12, 0.85);
  border: 1px solid rgba(224, 177, 79, 0.5);
  border-radius: 99px;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  z-index: 40;
}

/* ===========================================================================
   HUD
   ======================================================================== */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none; /* the game owns the mouse */
}

/* crosshair: a thin plus that stays visible on any backdrop */
#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  mix-blend-mode: difference;
}

#crosshair::before, #crosshair::after {
  content: "";
  position: absolute;
  background: #e8e8e8;
}

#crosshair::before {
  left: 50%;
  top: 0;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
}

#crosshair::after {
  top: 50%;
  left: 0;
  height: 2px;
  width: 100%;
  transform: translateY(-50%);
}

/* top-right status cluster */
.hud-corner {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--glass-soft);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  backdrop-filter: blur(10px);
  font-size: 0.85rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #888;
}

.status-dot.online { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-dot.offline { background: var(--danger); }
.status-dot.connecting {
  background: var(--warn);
  animation: pulse 1s ease-in-out infinite;
}

#status-ping { color: var(--ink-muted); }

/* debug overlay (F3) */
#debug {
  position: absolute;
  top: 14px;
  left: 14px;
  margin: 0;
  padding: 12px 14px;
  max-width: min(460px, 80vw);
  background: var(--glass-soft);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-small);
  backdrop-filter: blur(10px);
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* toasts */
#toasts {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast {
  padding: 9px 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: toast-in 220ms ease-out;
  white-space: nowrap;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast-warn { border-color: rgba(224, 177, 79, 0.55); color: #f4dfae; }
.toast-out { opacity: 0; transition: opacity 380ms; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* bottom bars: block hotbar + gear bar side by side, vitals floating above */
#bars {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#hotbar, #gearbar {
  display: flex;
  gap: 6px;
  padding: 8px;
  background: var(--glass-soft);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

/* gear slots reuse .hotbar-slot; these are the gear-only extras */
.gear-count {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.68rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.hotbar-slot.worn {
  border-color: #8fb7dd;
  box-shadow: inset 0 0 10px rgba(143, 183, 221, 0.35);
}

.hotbar-slot.worn::after {
  content: "worn";
  position: absolute;
  top: 1px;
  right: 4px;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #bcd9f2;
  text-transform: uppercase;
}

/* vitals: hearts + armor chip, hugging the bars' top-left corner */
#vitals {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--glass-soft);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  backdrop-filter: blur(10px);
}

#hearts {
  display: flex;
  gap: 2px;
  font-size: 0.95rem;
  line-height: 1;
}

.heart { color: #e8453a; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.heart.half {
  background: linear-gradient(90deg, #e8453a 50%, rgba(255, 255, 255, 0.16) 50%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.heart.empty { color: rgba(255, 255, 255, 0.16); }

#vitals.ouch #hearts { animation: hearts-ouch 360ms ease-out; }

@keyframes hearts-ouch {
  0% { transform: translateX(0); }
  25% { transform: translateX(-3px) scale(1.08); }
  55% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

#armor-chip { font-size: 0.95rem; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); }

/* damage / heal edge flash */
#damage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 450ms ease-out;
  background: radial-gradient(ellipse at center,
    rgba(0, 0, 0, 0) 55%, rgba(196, 36, 24, 0.55) 100%);
}

#damage-vignette.hurt { opacity: 1; transition: opacity 60ms; }

#damage-vignette.healed {
  opacity: 1;
  transition: opacity 60ms;
  background: radial-gradient(ellipse at center,
    rgba(0, 0, 0, 0) 60%, rgba(96, 196, 92, 0.4) 100%);
}

/* knock-out overlay */
#death-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  background: radial-gradient(ellipse at center,
    rgba(64, 8, 4, 0.55) 0%, rgba(26, 4, 2, 0.82) 100%);
  animation: death-in 400ms ease-out;
}

#death-overlay h2 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  color: #f4c9c2;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}

@keyframes death-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* crosshair hit-marker pulse (landing a hit) */
#crosshair { transition: transform 120ms ease-out; }
#crosshair.hit { transform: translate(-50%, -50%) scale(1.45) rotate(45deg); }

.hotbar-slot {
  position: relative;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 100ms, background 100ms, transform 100ms;
}

.hotbar-slot:hover { background: rgba(255, 255, 255, 0.1); }

.hotbar-slot.selected {
  border-color: var(--accent);
  background: rgba(118, 201, 63, 0.14);
  transform: translateY(-3px);
}

.hotbar-slot canvas { display: block; }

.hotbar-key {
  position: absolute;
  top: 2px;
  left: 5px;
  font-size: 0.62rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.55);
}

/* selected-block name flash + hint bar (above the hotbar) */
#block-flash, #hint-bar {
  position: absolute;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  background: var(--glass-soft);
  border-radius: 99px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 300ms;
  white-space: nowrap;
}

#hint-bar {
  bottom: 124px;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

#block-flash.visible, #hint-bar.visible { opacity: 1; }

/* chat (bottom left) */
#chat {
  position: absolute;
  left: 14px;
  bottom: 16px;
  width: min(420px, 70vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#chat-log {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 36vh;
  overflow-y: auto;
  scrollbar-width: thin;
}

.chat-row {
  align-self: flex-start;
  max-width: 100%;
  padding: 5px 12px;
  background: var(--glass-soft);
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  transition: opacity 600ms;
}

.chat-row.chat-faded { opacity: 0; }
#chat.chat-open .chat-row { opacity: 1; }

.chat-name { font-weight: 600; color: var(--accent-strong); margin-right: 7px; }
.chat-name.chat-self { color: #9fd0ff; }
.chat-system { color: var(--ink-muted); font-style: italic; }

#chat-form { display: none; }
#chat.chat-open #chat-form { display: block; pointer-events: auto; }

#chat-input {
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-small);
  outline: none;
}

#chat-input:focus { border-color: var(--accent); }

/* hold-Tab player roster */
#player-list {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 220px;
  max-width: min(420px, 80vw);
  padding: 14px 20px 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

#player-list h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.player-row {
  padding: 3px 0;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-row.player-self { color: var(--accent-strong); }

/* underwater tint */
#underwater {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 60%,
    rgba(20, 70, 140, 0.30), rgba(10, 40, 100, 0.55));
  opacity: 0;
  transition: opacity 250ms;
}

#underwater.visible { opacity: 1; }

/* --- misc --------------------------------------------------------------- */

.noscript-note {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #101713;
  color: var(--ink);
  font-family: var(--font);
  z-index: 100;
}

.pause-card { text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .screen, .overlay, .toast { animation: none; }
  .ready-cta, .status-dot.connecting { animation: none; }
}
