:root {
  --bg-glass: rgba(15, 23, 42, 0.84);
  --bg-card: rgba(30, 41, 59, 0.82);
  --bg-card-hover: rgba(51, 65, 85, 0.9);
  --border: rgba(148, 163, 184, 0.22);
  --accent: #4ade80;
  --accent-dark: #16a34a;
  --blue: #38bdf8;
  --danger: #ef4444;
  --text: #f8fafc;
  --muted: #94a3b8;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
input, select, textarea { user-select: text; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: #0f172a;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.bold { font-weight: 700; }

/* ==================== MAIN MENU ==================== */
.overlay-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.28), rgba(15, 23, 42, 0.72));
  z-index: 20;
}

.menu-shell {
  width: min(1040px, 96vw);
  height: min(680px, 90vh);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.65);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-cube {
  width: 42px; height: 42px;
  border-radius: 8px;
  background: linear-gradient(180deg, #5da641 0% 34%, #866043 34% 100%);
  border: 2px solid #bbf7d0;
  box-shadow: 0 4px 14px rgba(74, 222, 128, 0.35);
}
.brand-title {
  font-family: 'Silkscreen', 'Noto Sans TC', monospace;
  font-size: 22px;
  letter-spacing: 1px;
  color: #fff;
}
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.header-account { display: flex; align-items: center; gap: 10px; }
.account-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border);
  font-size: 13px; cursor: pointer;
}
.avatar-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

.menu-body {
  flex: 1;
  display: grid;
  grid-template-columns: 210px 1fr;
  min-height: 0;
}

.menu-nav {
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 12px 14px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: #cbd5e1;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.15s ease; text-align: left;
}
.nav-btn:hover { background: rgba(51, 65, 85, 0.5); color: #fff; }
.nav-btn.active {
  background: rgba(74, 222, 128, 0.15);
  border-color: rgba(74, 222, 128, 0.45);
  color: #bbf7d0;
}
.nav-icon { font-size: 17px; }
.badge {
  margin-left: auto;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
}

.menu-content {
  padding: 22px 26px;
  overflow-y: auto;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 12px;
}
.panel-head h2 { font-size: 20px; }

.section-label {
  font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 16px 0 10px;
}

/* Cards & Lists */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.world-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color 0.15s, transform 0.15s;
}
.world-card:hover { border-color: rgba(74, 222, 128, 0.5); transform: translateY(-2px); }
.wc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.wc-title { font-size: 16px; font-weight: 700; }
.wc-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; }
.wc-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }

.tag {
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px;
}
.tag-survival { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.tag-creative { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; }
.tag-open { background: rgba(74, 222, 128, 0.2); color: #86efac; }
.tag-closed { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.tag-live { background: rgba(34, 197, 94, 0.28); color: #4ade80; }

.list-stack { display: flex; flex-direction: column; gap: 10px; }
.friend-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.friend-info { display: flex; align-items: center; gap: 12px; }
.avatar-md {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #0f172a; font-size: 16px;
}
.avatar-lg {
  width: 56px; height: 56px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: #0f172a; font-size: 24px;
}
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.status-online { background: #4ade80; }
.status-playing { background: #38bdf8; }
.status-offline { background: #64748b; }

.empty-box {
  background: rgba(30, 41, 59, 0.5);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

/* Forms & Buttons */
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; color: #cbd5e1; font-weight: 500; }
.form-row input, .form-row select, .inline-form input {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: #fff; font-size: 14px; outline: none;
}
.form-row input:focus, .form-row select:focus, .inline-form input:focus {
  border-color: var(--accent);
}
.color-input { height: 42px; padding: 4px !important; cursor: pointer; }

.inline-form { display: flex; gap: 10px; margin-bottom: 12px; }
.inline-form input { flex: 1; }

.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer; transition: all 0.15s;
}
.mode-card input { display: none; }
.mode-card.selected { border-color: var(--accent); background: rgba(74, 222, 128, 0.12); }
.mode-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.mode-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }

.toggle-box {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 15px;
}
.highlight-box { border-color: rgba(74, 222, 128, 0.45); background: rgba(22, 163, 74, 0.12); }
.toggle-title { font-weight: 700; font-size: 14px; }

.switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #475569; border-radius: 999px; transition: 0.2s;
}
.slider:before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--accent-dark); }
.switch input:checked + .slider:before { transform: translateX(22px); }

.btn {
  padding: 9px 15px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 700; cursor: pointer;
  transition: all 0.15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--accent-dark); color: #fff; }
.btn-primary:hover { background: #15803d; }
.btn-ghost { background: rgba(51, 65, 85, 0.65); border-color: var(--border); color: #e2e8f0; }
.btn-ghost:hover { background: rgba(71, 85, 105, 0.85); }
.btn-danger { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.45); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.35); }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 6px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

.subtabs { display: flex; gap: 8px; margin-bottom: 16px; }
.subtab {
  padding: 8px 16px; border-radius: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--muted); font-weight: 700; cursor: pointer;
}
.subtab.active { background: var(--accent-dark); color: #fff; border-color: transparent; }

.profile-card {
  display: flex; align-items: center; gap: 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 18px;
}

/* ==================== HUD ==================== */
#game-hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#damage-flash {
  position: fixed; inset: 0;
  background: radial-gradient(circle, transparent 50%, rgba(239, 68, 68, 0.55));
  opacity: 0; transition: opacity 0.15s;
}
#damage-flash.active { opacity: 1; }

#crosshair {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 24px; font-weight: 400; color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.9);
}

#mining-bar-wrap {
  position: fixed; top: calc(50% + 22px); left: 50%; transform: translateX(-50%);
  width: 64px; height: 6px; background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 3px; overflow: hidden;
}
#mining-bar-fill { height: 100%; width: 0%; background: var(--accent); }

.hud-top-left { position: fixed; top: 14px; left: 14px; display: flex; flex-direction: column; gap: 8px; }
.world-pill {
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: rgba(15, 23, 42, 0.72); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 12px; font-size: 13px; pointer-events: auto;
}
.pill-tag { font-size: 11px; padding: 2px 7px; border-radius: 5px; background: rgba(56, 189, 248, 0.25); color: #bae6fd; }
.pill-code {
  font-family: monospace; font-weight: 700; letter-spacing: 1px;
  background: rgba(255, 255, 255, 0.1); padding: 2px 7px; border-radius: 5px; cursor: pointer;
}
.pill-status { font-size: 11px; color: #86efac; }

.debug-panel {
  background: rgba(15, 23, 42, 0.75); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
  font-family: monospace; font-size: 12px; line-height: 1.5; color: #e2e8f0;
}

.hud-chat {
  position: fixed; bottom: 115px; left: 14px; width: min(360px, 80vw);
  display: flex; flex-direction: column; gap: 6px;
}
.chat-messages { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow: hidden; }
.chat-msg {
  background: rgba(15, 23, 42, 0.65); padding: 4px 9px; border-radius: 6px;
  font-size: 13px; line-height: 1.4; width: fit-content; max-width: 100%;
}
.chat-msg.system { color: #fde047; font-style: italic; }
.chat-form { pointer-events: auto; }
.chat-form input {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  background: rgba(15, 23, 42, 0.92); border: 1px solid var(--accent);
  color: #fff; font-size: 13px; outline: none;
}

.hud-bottom-center {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.held-item-name {
  font-size: 13px; font-weight: 700; text-shadow: 0 1px 4px #000; min-height: 18px;
}
.survival-bars { display: flex; justify-content: space-between; width: 100%; padding: 0 4px; gap: 20px; }
.stat-bar { font-size: 14px; letter-spacing: 1px; text-shadow: 0 1px 3px #000; }
.creative-badge {
  font-size: 12px; background: rgba(14, 165, 233, 0.35);
  border: 1px solid rgba(56, 189, 248, 0.5); padding: 2px 10px; border-radius: 999px;
}

.hotbar {
  display: flex; gap: 4px;
  background: rgba(15, 23, 42, 0.8);
  border: 2px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px; padding: 5px;
}

.slot {
  width: 48px; height: 48px;
  background: rgba(30, 41, 59, 0.85);
  border: 2px solid rgba(148, 163, 184, 0.25);
  border-radius: 7px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.slot.active {
  border-color: #ffffff;
  background: rgba(74, 222, 128, 0.25);
  transform: scale(1.06);
}
.slot.selected-swap { border-color: #facc15; box-shadow: 0 0 0 2px #facc15; }
.slot img { width: 34px; height: 34px; image-rendering: pixelated; }
.slot-count {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 11px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000;
}
.slot-key {
  position: absolute; top: 1px; left: 4px;
  font-size: 10px; color: rgba(255, 255, 255, 0.45);
}

.hud-controls-hint {
  position: fixed; bottom: 14px; right: 14px;
  background: rgba(15, 23, 42, 0.58); border-radius: 8px;
  padding: 6px 10px; font-size: 11px; color: #cbd5e1; line-height: 1.5; text-align: right;
}

/* ==================== MODALS ==================== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.72); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 30;
}
.modal-card {
  width: min(520px, 95vw); max-height: 90vh; overflow-y: auto;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 20px 22px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
.modal-wide { width: min(820px, 95vw); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.inv-grid-layout { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; }
.slot-grid { display: grid; grid-template-columns: repeat(9, 48px); gap: 5px; }
.catalog-grid { grid-template-columns: repeat(auto-fill, 54px); gap: 8px; }
.catalog-grid .slot { width: 54px; height: 54px; }

.crafting-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 360px; overflow-y: auto; padding-right: 4px;
}
.craft-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px;
}
.craft-info { display: flex; align-items: center; gap: 10px; }
.craft-info img { width: 28px; height: 28px; image-rendering: pixelated; }
.craft-req { font-size: 11px; color: var(--muted); }

.pause-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg-card); border-radius: 10px; padding: 10px 14px;
}
.code-big { font-family: monospace; font-size: 20px; font-weight: 900; letter-spacing: 3px; color: var(--accent); }
.pause-section { background: var(--bg-card); border-radius: 10px; padding: 12px 14px; }
.player-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.player-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(15, 23, 42, 0.7); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
}
.settings-sliders { display: flex; flex-direction: column; gap: 10px; }
.settings-sliders label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.pause-footer { display: flex; justify-content: space-between; gap: 10px; }
.death-card { text-align: center; border-color: rgba(239, 68, 68, 0.5); }
.death-card h2 { color: #f87171; font-size: 28px; }

#toast-container {
  position: fixed; top: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 8px; z-index: 50;
}
.toast {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--accent);
  color: #fff; padding: 10px 15px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast.error { border-color: var(--danger); color: #fecaca; }

@media (max-width: 820px) {
  .menu-body { grid-template-columns: 1fr; }
  .menu-nav { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .inv-grid-layout { grid-template-columns: 1fr; }
  .hud-controls-hint { display: none; }
}
