:root {
  --bg: #14161b;
  --panel: #1f232b;
  --ink: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #3a6ea5;
  --danger: #a53a3a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid #000;
}
.topbar .brand { font-weight: 700; color: var(--ink); text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--ink); }
.topbar .who { color: var(--muted); }

main { padding: 1rem; }

a { color: #6ea8e0; }

.card {
  background: var(--panel);
  border-radius: 10px;
  padding: 1.5rem;
  max-width: 1100px;
  margin: 1rem auto;
}
.card.centered { max-width: 520px; text-align: center; }
.card section { margin: 1.5rem 0; }

h1 { margin-top: 0; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}
button:hover { filter: brightness(1.1); }
button.danger { background: var(--danger); }

/* A link that looks like a button (e.g. "Return to table"). */
.button-link {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  font-size: 0.95rem;
}
.button-link:hover { filter: brightness(1.1); }

input, select {
  background: #11141a;
  color: var(--ink);
  border: 1px solid #333;
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  font-size: 0.95rem;
}

.join-form, .upload-form, .dev-login { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.dev-login { flex-direction: column; align-items: center; margin-top: 1rem; }

.warn { color: #e6b35a; }
.hint { color: var(--muted); font-size: 0.85rem; }

.quota { color: var(--muted); }

/* Library grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.thumb {
  margin: 0;
  background: #11141a;
  border-radius: 8px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.thumb img { width: 100%; height: 120px; object-fit: contain; background: #000; border-radius: 4px; }
.thumb .fn { display: block; font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb .meta { display: block; font-size: 0.72rem; color: var(--muted); }

/* Table layout */
.table-layout { display: flex; gap: 1rem; height: calc(100vh - 90px); position: relative; }
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--panel);
  border-radius: 10px;
  padding: 1rem;
  overflow-y: auto;
}
.sidebar section { margin: 1.1rem 0; }
.sidebar h2 { margin-top: 0; font-size: 1.1rem; }
.sidebar h3 { font-size: 0.9rem; margin-bottom: 0.4rem; }
.sidebar select { width: 100%; margin-bottom: 0.4rem; }
.sidebar button { width: auto; margin-top: 0.2rem; }
.code { background: #000; padding: 0.1rem 0.4rem; border-radius: 4px; letter-spacing: 2px; }

.canvas-wrap {
  flex: 1;
  min-width: 0;            /* let the canvas shrink/grow inside the flex row */
  position: relative;      /* anchor for the floating sidebar toggle */
  background: #0c0e12;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#board { max-width: 100%; max-height: 100%; touch-action: none; cursor: grab; }

/* Floating menu toggle, overlaid on the canvas top-left so it's reachable in
   either state. */
.sidebar-toggle {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 5;
  width: auto;
  padding: 0.45rem 0.8rem;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  background: var(--accent);
  border: 1px solid #000;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

/* The floating opener only matters while collapsed; when the sidebar is open
   the close control lives inside the panel header instead (so it can't get
   covered by the panel on a tight mobile screen). */
.table-layout:not(.sidebar-collapsed) .sidebar-toggle { display: none; }

/* Close (✕) button sitting inline with the table code in the sidebar header. */
.table-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-close {
  flex-shrink: 0;
  margin-top: 0;
  padding: 0.3rem 0.6rem;
  font-size: 1rem;
  line-height: 1;
}

/* Collapsed: drop the sidebar entirely; the canvas reclaims the full width. */
.table-layout.sidebar-collapsed .sidebar { display: none; }

/* On phones the sidebar would swallow most of the screen, so make it an
   overlay when shown rather than a column that squeezes the map. */
@media (max-width: 700px) {
  .table-layout { height: calc(100vh - 70px); }
  .table-layout .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    width: min(280px, 85vw);
    height: 100%;
  }
  /* Bigger tap targets for fingers. */
  .sidebar button, .sidebar select { padding: 0.7rem 0.8rem; font-size: 1rem; }
  .sidebar-toggle { padding: 0.6rem 0.8rem; font-size: 1.3rem; }
}
