* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:        #1a1a2e;
  --surface:   #16213e;
  --panel:     #0f3460;
  --accent:    #e94560;
  --text:      #eaeaea;
  --muted:     #8899aa;
  --green:     #a8ff78;
  --gold:      #f5c518;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  /* overflow:hidden removed — main handles it; body overflow:hidden breaks
     position:fixed on iOS Safari when combined with height:100vh */
}

/* ─── Header ────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 2px solid var(--panel);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative; /* for absolutely-centered weather */
}

header h1 {
  font-size: 1.4rem;
  color: var(--gold);
  letter-spacing: 2px;
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ── Desktop nav links — pushed to far right ── */
#nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto; /* pushes nav to right edge */
  flex-shrink: 0;
}
#nav-links a {
  color: var(--muted);
  font-size: .8rem;
  text-decoration: none;
}

/* ── Weather banner — icon-only, absolutely centered in header on desktop ── */
#weather-indicator {
  font-size: 1.1rem;
  padding: 0 8px;
  cursor: default;
  display: none;
  align-items: center;
  flex-shrink: 0;
  border-left: 1px solid rgba(255,255,255,.1);
}

/* Weather icon: only in toolbar now */

/* ── Balance + Username — desktop ── */
.header-username {
  color: var(--gold);
  font-size: .9rem;
  flex-shrink: 0;
}
.header-balance {
  font-size: 1.0rem;
  flex-shrink: 0;
}

#balance {
  color: var(--green);
  font-weight: bold;
}

/* ── Mobile right cluster: hidden on desktop ── */
#mobile-right-cluster { display: none; }

/* ── Hamburger button (mobile only) ── */
#hamburger-btn {
  display: none;
}

/* ── Nav drawer (mobile slide-in) ── */
#nav-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1800;
}
#nav-drawer-overlay.open { display: block; }

#nav-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(280px, 85vw);
  background: var(--surface);
  border-left: 1px solid rgba(255,255,255,.1);
  z-index: 1900;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s ease;
  overflow: hidden;
}
#nav-drawer.open { transform: translateX(0); }

#nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
#nav-drawer-close {
  background: rgba(255,255,255,.08);
  border: none;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .95rem;
}
#nav-drawer-body {
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
}
.drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: .92rem;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background .15s;
}
.drawer-item:hover, .drawer-item:active { background: rgba(255,255,255,.08); }
.drawer-item[hidden] { display: none; }


/* ─── Toolbar ───────────────────────────────────────────────── */
/* ─── Toolbar (dropdown groups) ─────────────────────────────── */
#toolbar {
  display: flex;
  gap: 4px;
  align-items: center;
  background: var(--surface);
  padding: 5px 10px;
  border-bottom: 1px solid var(--panel);
  flex-shrink: 0;
  overflow-x: auto;
  flex-wrap: nowrap;
  position: relative;
  z-index: 200;
}

/* Group wrapper — must be position:relative for the dropdown */
.toolbar-group {
  position: relative;
}

/* The clickable group trigger button */
.group-trigger {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2a4a7a;
  border-radius: 6px;
  padding: 6px 11px;
  cursor: pointer;
  font-size: .85rem;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
  user-select: none;
}
.group-trigger:hover  { background: #1a3a5a; border-color: var(--accent); }
.toolbar-group.open > .group-trigger { background: var(--accent); border-color: var(--accent); color:#fff; border-bottom-left-radius:0; border-bottom-right-radius:0; }
.group-name { font-size: .82rem; }
.chevron    { font-size: .65rem; opacity: .7; }

/* Dropdown panel — position:fixed escapes overflow:auto clipping */
.group-panel {
  display: none;
  position: fixed;   /* NOT absolute — must escape toolbar overflow */
  min-width: 210px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 0 6px 6px 6px;
  box-shadow: 0 8px 28px rgba(0,0,0,.6);
  z-index: 9100;
  padding: 4px;
  flex-direction: column;
  gap: 2px;
}
.toolbar-group.open > .group-panel { display: flex; }
.group-panel.open { display: flex; }

/* Sub-section header inside dropdown */
.tool-subheader {
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gold);
  padding: 6px 8px 2px;
  border-top: 1px solid rgba(255,255,255,.08);
  margin-top: 2px;
  opacity: .85;
  pointer-events: none;
}
.tool-subheader:first-child { border-top: none; margin-top: 0; padding-top: 2px; }

/* ── Favorites ─────────────────────────────────────────────────────── */

/* Star toggle inside each dropdown tool button */
.fav-star {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .8rem;
  padding: 0 1px 0 4px;
  opacity: .3;
  transition: opacity .15s, transform .1s;
  margin-left: auto;
  flex-shrink: 0;
  line-height: 1;
}
.fav-star:hover { opacity: .8; transform: scale(1.15); }
.fav-star.active { opacity: 1; }

/* Separator before the favorites quick bar */
.fav-sep {
  width: 1px;
  background: rgba(255,255,255,.18);
  align-self: stretch;
  margin: 4px 4px;
  flex-shrink: 0;
}

/* Quick-access buttons in toolbar (right of Market) */
.fav-quick-btn {
  background: rgba(74,144,226,.12);
  border: 1px solid rgba(74,144,226,.22);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  padding: 3px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .8rem;
  transition: background .12s;
  white-space: nowrap;
  flex-shrink: 0;
}
.fav-quick-btn:hover  { background: rgba(74,144,226,.3); border-color: var(--accent); }
.fav-quick-btn.active { background: rgba(74,144,226,.42); border-color: var(--accent); font-weight: 600; }
.fav-quick-btn.fav-action { border-color: rgba(255,200,50,.4); }
.fav-quick-btn.fav-action:hover { background: rgba(255,180,30,.2); border-color: rgba(255,200,50,.8); }
.fav-icon  { font-size: .9rem; }
.fav-label { font-size: .74rem; }

/* ── Alert Log (bottom-left) ────────────────────────────────────────── */
#alert-log {
  position: fixed;
  bottom: 70px;
  left: 16px;
  z-index: 1998;
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  max-width: 290px;
  pointer-events: none;
}
.alert-item {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(14,24,16,.95);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  font-size: .8rem;
  pointer-events: all;
  animation: alertIn .22s ease;
  box-shadow: 0 3px 12px rgba(0,0,0,.5);
}
.alert-harvest { border-left: 3px solid #4a9e6b; }
.alert-pest    { border-left: 3px solid #c97c2a; }
.alert-wither  { border-left: 3px solid #8b3030; }
.alert-world   { border-left: 3px solid #4a90e2; }
.alert-achievement { border-left: 3px solid #f5c518; }
.alert-info    { border-left: 3px solid var(--accent); }
.alert-icon    { font-size: .95rem; flex-shrink: 0; }
.alert-msg     { flex: 1; line-height: 1.3; }
.alert-close   { background: none; border: none; cursor: pointer; color: var(--muted);
                 font-size: .65rem; padding: 0 0 0 4px; flex-shrink: 0; opacity: .6; }
.alert-close:hover { opacity: 1; }
.alert-out     { opacity: 0; transform: translateX(-10px); transition: opacity .28s, transform .28s; }
@keyframes alertIn {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Tool button inside dropdown */
.tool-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: .83rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .1s;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}
.tool-btn:hover  { background: #1a3a5a; border-color: var(--accent); }
.tool-btn.active { background: rgba(74,144,226,.25); border-color: var(--accent); font-weight:600; }
.tool-icon  { font-size: 1rem; width: 1.2em; text-align: center; flex-shrink:0; }
.tool-label { flex: 1; font-size: .82rem; }
.tool-cost  { font-size: .68rem; color: var(--gold); opacity: .85; white-space:nowrap; }

/* Action items in the Actions dropdown */
.action-item { border-color: rgba(60,200,100,.25); }
.action-item:hover { background: rgba(40,160,80,.2); border-color: #3cc860; }

/* Actions group trigger */
.action-trigger {
  background: #1a3a20 !important;
  border-color: #2a6a30 !important;
}
.action-trigger:hover { background: #223a28 !important; border-color: #3a8a40 !important; }
.toolbar-group.open > .action-trigger { background: #2a6a30 !important; border-color: #3a8a40 !important; }

/* Market trigger */
.market-btn {
  background: #1a4a1a !important;
  border-color: #2a7a2a !important;
  margin-left: 6px;
}
.market-btn:hover { background: #2a6a2a !important; border-color: #4aaa4a !important; }

/* ─── Tooltip ────────────────────────────────────────────────── */
#tool-tooltip {
  position: absolute;
  z-index: 9000;
  background: #0e1e38;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 13px;
  width: 260px;
  box-shadow: 0 6px 24px rgba(0,0,0,.6);
  pointer-events: none;
  font-size: .8rem;
  line-height: 1.45;
}
#tool-tooltip[hidden] { display: none; }
.tt-header { display:flex; align-items:baseline; gap:7px; margin-bottom:6px; }
.tt-icon   { font-size: 1.1rem; }
.tt-title  { font-weight:700; font-size:.9rem; color:var(--text); flex:1; }
.tt-cost   { font-size:.72rem; color:var(--gold); font-weight:600; }
.tt-body   { color:var(--muted); font-size:.78rem; line-height:1.5; }


/* ─── Market modal ───────────────────────────────────────────── */
#market-modal .modal-box {
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 22px 24px 16px;
  gap: 0;
}
#market-modal .mkt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}
#market-modal .tab-row {
  margin-bottom: 10px;
  flex-shrink: 0;
}
#market-content {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ─── Market modal table ─────────────────────────────────────── */
.market-table { width:100%; border-collapse:collapse; font-size:.85rem; }
.market-table thead { position:sticky; top:0; background:var(--surface); z-index:1; }
.market-table th { text-align:left; padding:6px 10px; border-bottom:2px solid var(--border); color:var(--muted); font-size:.72rem; text-transform:uppercase; letter-spacing:.05em; }
.market-table td { padding:7px 10px; border-bottom:1px solid rgba(255,255,255,.04); vertical-align:middle; }
.market-table tr:hover td { background:rgba(255,255,255,.03); }
.market-table tr:last-child td { border-bottom:none; }
.mkt-sell-btn { background:var(--accent); color:#fff; border:none; border-radius:4px; padding:4px 10px; cursor:pointer; font-size:.78rem; font-weight:600; white-space:nowrap; }
.mkt-sell-btn:hover { opacity:.85; }
.mkt-sell-btn:disabled { opacity:.35; cursor:default; }
.mkt-qty-input { background:rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.2); border-radius:4px; color:var(--text); text-align:right; }
.mkt-qty-input:focus { outline:none; border-color:var(--accent); }
.mkt-sell-bulk { background:#5a3a00; color:var(--gold); border:1px solid var(--gold); border-radius:4px; padding:3px 8px; cursor:pointer; font-size:.75rem; font-weight:600; white-space:nowrap; }
.mkt-sell-bulk:hover { background:#7a5000; }
.mkt-group-hdr { background:rgba(255,255,255,.06) !important; font-weight:600; font-size:.8rem; }
.mkt-group-hdr td { padding:6px 10px; border-bottom:1px solid var(--border) !important; }
.market-note { font-size:.72rem; color:var(--muted); margin-top:8px; font-style:italic; padding:0 2px; }
.mkt-total-bar { display:flex; justify-content:space-between; align-items:center; padding:8px 4px; border-top:1px solid var(--border); margin-top:6px; font-size:.82rem; flex-shrink:0; }
.mkt-total-bar strong { color:var(--gold); }
.mkt-sell-all-btn { background:linear-gradient(135deg,#2a8a2a,#3aaa3a); color:#fff; border:none; border-radius:5px; padding:5px 14px; cursor:pointer; font-size:.82rem; font-weight:700; }
.mkt-sell-all-btn:hover { opacity:.9; }
.mkt-price-up   { color:#4aff4a; font-size:.78rem; }
.mkt-price-down { color:#ff6644; font-size:.78rem; }
.mkt-price-flat { color:var(--muted); font-size:.78rem; }

/* ─── Tab row (shared by login page + market modal) ─────────── */
.tab-row { display:flex; gap:0; border-radius:6px; overflow:hidden; border:1px solid var(--border); }
.tab-btn.active { background:var(--accent); color:#fff; font-weight:600; }


/* ─── Inventory panel ─────────────────────────────────────────── */
.inv-row { display:flex; justify-content:space-between; font-size:.78rem; padding:3px 0; border-bottom:1px solid rgba(255,255,255,.05); }
.inv-qty { color:var(--gold); font-weight:600; }

/* ─── Weather indicator in toolbar — display rule ──────────────────────────── */
#weather-indicator[data-type] { display:flex!important; }

/* ─── Main layout ───────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

#canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 16px;
  background: var(--bg);
}

#farm-canvas {
  display: block;
  border: 2px solid var(--panel);
  border-radius: 4px;
  cursor: crosshair;
  image-rendering: pixelated;
  max-width: 100%;
}

/* ─── Side panel ────────────────────────────────────────────── */
#side-panel {
  width: 220px;
  background: var(--surface);
  border-left: 1px solid var(--panel);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  position: relative;
  transition: width 0.2s ease, padding 0.2s ease;
  flex-shrink: 0;
}

#side-panel.collapsed {
  width: 28px;
  padding: 4px 0;
  overflow: hidden;
  gap: 0;
}

#side-panel.collapsed #side-content {
  display: none;
}

#side-toggle {
  position: absolute;
  top: 8px;
  left: 4px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 2px 5px;
  z-index: 5;
  transition: left 0.2s ease;
}

#side-panel.collapsed #side-toggle {
  left: 2px;
  transform: rotate(180deg);
}

#side-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
}

#side-panel h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  border-bottom: 1px solid var(--panel);
  padding-bottom: 4px;
}

#tile-info {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
}

/* Legend */
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  margin: 4px 0;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
}

#refresh-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #2a4a7a;
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  width: 100%;
  transition: background 0.15s;
}

#refresh-btn:hover { background: #1a3a5a; }

/* ─── Status bar ────────────────────────────────────────────── */
footer {
  background: var(--surface);
  border-top: 1px solid var(--panel);
  padding: 5px 20px;
  font-size: 0.8rem;
  color: var(--muted);
  flex-shrink: 0;
  display: flex;
  gap: 20px;
}

#status-msg {
  color: var(--green);
  transition: color 0.3s;
}

/* ─── Auth Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--panel);
  border-radius: 12px;
  padding: 36px 40px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-logo { font-size: 2rem; text-align: center; margin-bottom: 4px; }
.modal-box h2 { text-align: center; color: var(--gold); font-size: 1.2rem; margin-bottom: 4px; }
.modal-box input {
  background: var(--bg);
  border: 1px solid var(--panel);
  border-radius: 6px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.modal-box input:focus { border-color: var(--accent); }
.auth-error { color: #ff6b6b; font-size: 0.82rem; min-height: 18px; text-align: center; }
.modal-btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.modal-btn-primary:hover { opacity: 0.85; }
.modal-btn-primary:disabled { opacity: 0.5; cursor: default; }
.modal-btn-text { background: none; border: none; color: var(--muted); font-size: 0.8rem; cursor: pointer; text-align: center; }
.modal-btn-text:hover { color: var(--text); }

/* ─── Toolbar ────────────────────────────────────────────────── */
.toolbar-sep { color: var(--panel); padding: 0 4px; user-select: none; font-size: 1.2rem; align-self: center; }
.livestock-tool { border-color: #2a6a2a; }
.livestock-tool.active { background: #2a8a2a; border-color: #2a8a2a; }
.livestock-tool:hover { border-color: #4aaa4a; }
.tool-label { font-size: 0.78rem; }

/* ─── Livestock panel (compact) ──────────────────────────────── */
.ls-summary     { display:flex; flex-wrap:wrap; gap:5px; padding:3px 0 6px; }
.ls-count-tag   { background:rgba(255,255,255,.06); border-radius:4px; padding:2px 7px; font-size:.78rem; color:var(--gold); }
.ls-scroll      { max-height:150px; overflow-y:auto; scrollbar-width:thin; }
.ls-row         { display:flex; align-items:center; gap:5px; font-size:.72rem; padding:3px 2px; border-bottom:1px solid rgba(255,255,255,.04); cursor:pointer; border-radius:3px; transition:background .15s; }
.ls-row:hover   { background:rgba(255,255,255,.06); }
.ls-row-active  { background:rgba(255,220,50,.15) !important; outline:1px solid rgba(255,220,50,.5); }
.ls-name        { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.72rem; }
.ls-hp          { font-size:.66rem; font-weight:700; white-space:nowrap; }
.ls-hunger      { font-size:.66rem; white-space:nowrap; }
.ls-prod        { font-size:.66rem; color:var(--muted); white-space:nowrap; }
/* ─── Farm events panel ──────────────────────────────────────── */
#events-panel   { font-size:.72rem; }
.ev-row         { display:flex; align-items:baseline; gap:5px; padding:3px 0; border-bottom:1px solid rgba(255,255,255,.04); }
.ev-icon        { flex-shrink:0; }
.ev-desc        { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.7rem; color:#ccc; }
.ev-time        { flex-shrink:0; font-size:.63rem; color:var(--muted); }
/* ─── Legacy big cards (kept for reference, unused) ─────────── */
.livestock-row  { display:none; }

/* ─── Chat Drawer ─────────────────────────────────────────────────────────── */
#chat-drawer      { position:fixed; bottom:0; left:20px; z-index:2000; font-size:.85rem; }
#chat-toggle-btn  { position:relative; background:#1a4a2a; border:1px solid rgba(255,255,255,.15);
                    color:#fff; padding:7px 16px; border-radius:8px 8px 0 0; cursor:pointer;
                    font-size:.88rem; user-select:none; }
#chat-toggle-btn:hover { background:#2a6a3a; }
#chat-panel       { display:none; flex-direction:column; width:340px; height:440px;
                    background:#121e14; border:1px solid rgba(255,255,255,.12); border-bottom:none;
                    border-radius:8px 8px 0 0; overflow:hidden; box-shadow:0 -4px 20px rgba(0,0,0,.5); }
#chat-panel.open  { display:flex; }
#chat-header      { display:flex; align-items:center; background:rgba(255,255,255,.05);
                    padding:6px 10px; gap:6px; flex-shrink:0; }
.chat-tabs        { display:flex; gap:4px; flex:1; overflow:hidden; }
.chat-tab         { background:none; border:none; color:var(--muted); font-size:.75rem;
                    padding:4px 8px; border-radius:4px; cursor:pointer; white-space:nowrap; }
.chat-tab.active  { background:rgba(255,255,255,.08); color:var(--text); }
#chat-close-btn   { background:none; border:none; color:var(--muted); cursor:pointer; font-size:1rem;
                    line-height:1; flex-shrink:0; }
#chat-body        { flex:1; overflow:hidden; display:flex; flex-direction:column; }
.chat-pane        { display:flex; flex-direction:column; height:100%; padding:8px; overflow:hidden; }
.chat-pane.hidden { display:none; }
.chat-messages    { flex:1; overflow-y:auto; scrollbar-width:thin; padding:2px 0 4px; }
.chat-input-row   { display:flex; gap:5px; margin-top:6px; flex-shrink:0; }
.chat-input-row input { flex:1; background:rgba(255,255,255,.07); border:1px solid rgba(255,255,255,.12);
                         color:var(--text); border-radius:5px; padding:5px 8px; font-size:.8rem; }
.chat-input-row button { background:var(--accent); border:none; color:#fff; border-radius:5px;
                          padding:5px 10px; cursor:pointer; font-size:.78rem; white-space:nowrap; }
.chat-msg         { display:flex; gap:7px; padding:4px 2px; }
.chat-msg.self    { flex-direction:row-reverse; }
.chat-avatar      { width:24px; height:24px; border-radius:5px; display:flex; align-items:center;
                    justify-content:center; font-size:.9rem; flex-shrink:0; }
.chat-msg-body    { max-width:75%; }
.chat-msg.self .chat-msg-body { align-items:flex-end; display:flex; flex-direction:column; }
.chat-msg-name    { font-size:.65rem; color:var(--muted); }
.chat-msg-time    { font-size:.6rem; color:rgba(255,255,255,.3); margin-left:4px; }
.chat-msg-text    { background:rgba(255,255,255,.07); border-radius:5px; padding:4px 8px;
                    font-size:.78rem; word-break:break-word; margin-top:2px; }
.chat-msg.self .chat-msg-text { background:rgba(60,120,60,.35); }
.chat-sys-msg     { font-size:.72rem; text-align:center; padding:3px 0; }
.chat-badge       { background:#e74c3c; color:#fff; border-radius:8px; padding:1px 5px;
                    font-size:.65rem; font-weight:700; }
.chat-badge.hidden { display:none; }
.chat-section     { margin-bottom:4px; }
.chat-section-label { font-size:.7rem; color:var(--muted); margin-bottom:4px; text-transform:uppercase; letter-spacing:.04em; }
.chat-muted       { font-size:.75rem; color:var(--muted); }
.friend-row       { display:flex; align-items:center; gap:6px; padding:5px 2px;
                    border-bottom:1px solid rgba(255,255,255,.04); font-size:.78rem; }
.friend-avatar    { width:22px; height:22px; border-radius:4px; display:flex; align-items:center;
                    justify-content:center; font-size:.85rem; flex-shrink:0; }
.friend-name      { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.online-dot       { color:#2ecc71; font-size:.7rem; flex-shrink:0; }
.offline-dot      { color:#666; font-size:.7rem; flex-shrink:0; }
.dm-btn           { background:rgba(60,120,60,.4); border:none; color:#9f9; border-radius:4px;
                    padding:2px 7px; cursor:pointer; font-size:.7rem; flex-shrink:0; }
.rm-btn           { background:none; border:none; color:var(--muted); cursor:pointer; font-size:.75rem; flex-shrink:0; }
.accept-btn       { background:rgba(60,120,60,.4); border:none; color:#9f9; border-radius:4px;
                    padding:2px 7px; cursor:pointer; font-size:.7rem; flex-shrink:0; }

/* ── Toggle switch (used in admin config) ─────────────────────── */
.toggle-switch         { position:relative; display:inline-block; width:42px; height:22px; flex-shrink:0; }
.toggle-switch input   { opacity:0; width:0; height:0; }
.toggle-slider         { position:absolute; cursor:pointer; inset:0; background:rgba(255,255,255,.15);
                         border-radius:22px; transition:.2s; }
.toggle-slider::before { content:''; position:absolute; width:16px; height:16px; left:3px; bottom:3px;
                         background:#fff; border-radius:50%; transition:.2s; }
.toggle-switch input:checked + .toggle-slider         { background:var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform:translateX(20px); }

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (≤900px) and Mobile (≤600px)
══════════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  /* Stack side panel below canvas on tablets */
  #game-layout { flex-direction: column !important; }
  #side-panel   { width: 100% !important; max-width: 100% !important; height: auto !important;
                  min-height: unset !important; border-left: none !important;
                  border-top: 1px solid rgba(255,255,255,.1); }
  #canvas-wrap  { flex: unset !important; width: 100% !important; }
  #game-canvas  { width: 100% !important; height: auto !important; }
  /* Toolbar wraps on tablet */
  #toolbar      { flex-wrap: wrap; gap: 4px; }
  .toolbar-group{ margin-bottom: 2px; }
}

/* ─── Mobile nav strip: removed (replaced by hamburger drawer) ── */
#mobile-nav-strip { display: none; }

@media (max-width: 600px) {
  /* ── Header: compact single row ── */
  #top-bar {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow: visible;
    position: relative;
  }
  /* Logo stays left */
  #top-bar .logo        { font-size: .88rem; white-space: nowrap; flex-shrink: 0; }
  /* Farm switcher: compact */
  #farm-switcher-wrap   { flex-shrink: 0; }
  #farm-switcher-btn    { font-size: .74rem; padding: 2px 7px; }

  /* Desktop elements: hide on mobile */
  .header-username      { display: none; }
  .header-balance       { display: none; }
  #nav-links            { display: none !important; }
  #quest-btn            { display: none !important; }
  #god-mode-icon        { display: none !important; }

  /* Mobile right cluster: username + balance + hamburger */
  #mobile-right-cluster {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
  }
  #mobile-user-balance {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
  }

  /* Hamburger button */
  #hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    padding: 6px;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 7px;
    cursor: pointer;
    flex-shrink: 0;
  }
  #hamburger-btn span {
    display: block;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: .2s;
  }

  /* Canvas height — no mobile nav strip anymore, just toolbar */
  #canvas-wrap  { height: calc(100vh - 90px); }
  #game-canvas  { width: 100% !important; max-width: 100% !important; }

  /* Toolbar: scrollable single row */
  #toolbar      { overflow-x: auto; flex-wrap: nowrap; padding: 4px; gap: 4px;
                  -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  /* Icon-only toolbar buttons — hide text labels and chevrons */
  .group-trigger .group-name { display: none; }
  .group-trigger .chevron    { display: none; }
  .group-trigger { padding: 6px 9px; font-size: 1.1rem; min-width: 36px;
                   display: inline-flex; align-items: center; justify-content: center; }
  #toolbar::-webkit-scrollbar { display: none; }


  /* ── Group panels → mobile bottom sheets ── */
  @keyframes sheet-slide-up {
    from { transform: translateY(28px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }

  .group-panel {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-height: 80vh !important;
    border-radius: 16px 16px 0 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-top: 2px solid var(--accent) !important;
    padding: 0 8px max(16px, env(safe-area-inset-bottom)) !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-content: flex-start !important;
    z-index: 9999 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    gap: 6px !important;
  }
  .toolbar-group.open > .group-panel {
    animation: sheet-slide-up .2s ease-out forwards !important;
  }
  .group-panel::before {
    content: '' !important;
    flex: 0 0 100% !important;
    height: 22px !important;
    background: no-repeat center / 40px 4px
                linear-gradient(rgba(255,255,255,.28), rgba(255,255,255,.28)) !important;
  }
  .group-panel .tool-subheader {
    width: 100% !important;
    flex: 0 0 100% !important;
    padding: 4px 4px 2px !important;
    margin-top: 2px !important;
  }
  .group-panel .tool-btn {
    flex: 1 1 calc(33.33% - 8px) !important;
    min-width: 82px !important;
    max-width: calc(33.33% - 4px) !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    text-align: center !important;
    gap: 4px !important;
    padding: 10px 4px !important;
    min-height: 68px !important;
    font-size: .72rem !important;
    white-space: normal !important;
    position: relative !important;
  }
  .group-panel .tool-icon  { font-size: 1.6rem !important; line-height: 1; width: auto !important; }
  .group-panel .tool-label { font-size: .64rem !important; text-align: center !important; flex: unset !important; }
  .group-panel .tool-cost  { font-size: .58rem !important; color: var(--gold) !important; }
  .group-panel .fav-star   { position: absolute !important; top: 3px !important; right: 3px !important;
                              font-size: .6rem !important; min-height: unset !important;
                              padding: 0 !important; margin: 0 !important; line-height: 1 !important; }

  /* ── Backdrop for bottom sheet ── */
  #mobile-panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 9998;
  }
  #mobile-panel-backdrop.visible { display: block; }

  /* Side panel */
  #side-panel   { position: fixed !important; bottom: 0; left: 0; right: 0; z-index: 500;
                  width: 100% !important; max-height: 45vh; overflow-y: auto;
                  transform: translateY(100%); transition: transform .3s ease;
                  border-radius: 14px 14px 0 0; border-top: 2px solid var(--accent); }
  #side-panel.mobile-open { transform: translateY(0); }
  #mobile-panel-btn { display: flex !important; }

  /* Chat drawer compact */
  .chat-drawer  { width: 100% !important; right: 0 !important; left: 0 !important; }
  #chat-panel   { width: 100% !important; border-radius: 14px 14px 0 0; }

  /* Modals full-width */
  .modal-overlay .modal-box { width: 95vw !important; max-width: 95vw !important; }
  #farm-selector-panel { width: 95vw; }
}


/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
  .tool-btn     { min-height: 44px; padding: 8px 12px; }
  .group-trigger{ min-height: 44px; }
  button        { min-height: 36px; }
}

/* ─── Achievement toasts ──────────────────────────────────────────────── */
#achievement-container {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.achievement-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #1a1000, #2e2200);
  border: 2px solid #f0c000;
  border-radius: 12px;
  padding: 12px 16px;
  min-width: 230px;
  max-width: 300px;
  box-shadow: 0 4px 24px rgba(240,192,0,.45), 0 2px 8px rgba(0,0,0,.6);
  color: #fff;
  transform: translateX(120%);
  opacity: 0;
  transition: transform .4s cubic-bezier(.175,.885,.32,1.275), opacity .4s;
}
.achievement-toast.ach-show { transform: translateX(0); opacity: 1; }
.achievement-toast.ach-hide { transform: translateX(120%); opacity: 0; transition: transform .4s ease-in, opacity .4s; }
.ach-icon   { font-size: 1.8rem; flex-shrink: 0; filter: drop-shadow(0 0 6px #f0c000); }
.ach-header { font-size: .62rem; color: #f0c000; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 2px; }
.ach-label  { font-size: .88rem; font-weight: 600; line-height: 1.2; }
@media (max-width: 600px) {
  #achievement-container { bottom: 70px; right: 8px; }
  .achievement-toast { min-width: 180px; font-size: .8rem; }
}
