/* ---------------------------------------------------------------
   Damp: a window on a wet night.
   Cold slate for the glass, pale mist for the type, and one
   sodium-lamp amber that marks what is selected or what to press.
   --------------------------------------------------------------- */
:root {
  --night: #16222b;
  --deep: #0e171d;
  --pane: #1e2e3a;
  --pane-hi: #263948;
  --line: #2d4050;
  --mist: #dfe8e8;
  --fog: #8fa4ac;
  --lamp: #e9b44c;
  --lamp-ink: #1a1405;
  --bad: #ee8b93;
  --display: "Big Shoulders Display", "Barlow Condensed", "Arial Narrow", Impact, sans-serif;
  --text: "Schibsted Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--text);
  font-size: 1rem;
  background: var(--night);
  color: var(--mist);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.locked { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
a { color: var(--mist); }
::selection { background: var(--lamp); color: var(--lamp-ink); }

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

.wrap {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 28px;
}

/* ----- Top bar ----- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--deep);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--mist);
  font-family: var(--display);
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1;
  text-decoration: none;
}

.logo svg { width: 20px; height: 24px; flex: none; }
.logo path { fill: var(--lamp); }

#search {
  flex: 1;
  min-width: 0;
  max-width: 460px;
  height: 42px;
  margin-left: 12px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--night);
  color: var(--mist);
  font: inherit;
  transition: border-color 0.15s;
}

#search::placeholder { color: var(--fog); }
#search:hover { border-color: #3d5568; }
#search:focus-visible { outline-offset: 0; border-color: var(--lamp); }

#random {
  margin-left: auto;
  height: 42px;
  padding: 0 20px;
  border: 0;
  border-radius: 4px;
  background: var(--lamp);
  color: var(--lamp-ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

#random:hover { background: #f3c569; }

#account,
#add-game {
  height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#account:hover,
#add-game:hover { border-color: var(--fog); background: var(--pane); }

/* ----- Page: categories on the left, games on the right ----- */
main.wrap {
  flex: 1;
  display: grid;
  grid-template-columns: 188px minmax(0, 1fr);
  column-gap: 48px;
  row-gap: 0;
  align-items: start;
  padding-top: 36px;
  padding-bottom: 64px;
}

main.wrap:has(.chips[hidden]) { grid-template-columns: minmax(0, 1fr); }
main.wrap:has(.chips[hidden]) > * { grid-column: 1; }

.chips {
  grid-column: 1;
  grid-row: 1 / span 10;
  position: sticky;
  top: 96px;
  display: flex;
  flex-direction: column;
}

.shelf, .head, .grid, .empty { grid-column: 2; }
main.wrap:has(.chips[hidden]) > .shelf,
main.wrap:has(.chips[hidden]) > .head,
main.wrap:has(.chips[hidden]) > .grid,
main.wrap:has(.chips[hidden]) > .empty { grid-column: 1; }

/* The selected category is marked by a lamp-coloured edge, like a lit window */
.chip {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 9px 12px 9px 14px;
  border: 0;
  border-left: 2px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--fog);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}

.chip:hover { color: var(--mist); background: rgba(223, 232, 232, 0.04); }

.chip[aria-pressed="true"] {
  border-left-color: var(--lamp);
  background: var(--pane);
  color: var(--mist);
  font-weight: 700;
}

.chip .n {
  color: var(--fog);
  font-size: 0.88rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.chip[aria-pressed="true"] .n { color: var(--lamp); }

/* ----- Heading row ----- */
.head {
  display: flex;
  align-items: baseline;
  gap: 16px;
}

h1 {
  font-family: var(--display);
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.005em;
}

.count { white-space: nowrap; color: var(--fog); font-variant-numeric: tabular-nums; }
.empty { margin-top: 36px; color: var(--fog); }

#sort {
  margin-left: auto;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--night);
  color: var(--mist);
  font: inherit;
  font-size: 0.93rem;
  cursor: pointer;
}

#sort:hover { border-color: var(--fog); }

/* ----- Games ----- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(214px, 1fr));
  gap: 30px 20px;
  margin-top: 24px;
}

.item { min-width: 0; }

.game {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

.game:focus-visible { outline: none; }

.tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 10;
  border-radius: 4px;
  overflow: hidden;
  font-family: var(--display);
  font-size: 3.4rem;
  font-weight: 800;
  color: rgba(223, 232, 232, 0.8);
  background: hsl(var(--hue, 200) 22% 24%);
  outline: 1px solid rgba(223, 232, 232, 0.09);
  outline-offset: -1px;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game:focus-visible .tile {
  outline: 2px solid var(--lamp);
  outline-offset: 3px;
}

.game h3 {
  margin-top: 12px;
  font-size: 1.04rem;
  font-weight: 600;
  line-height: 1.25;
  transition: color 0.15s;
}

.game:hover h3,
.game:focus-visible h3 { color: var(--lamp); }

.game .cat {
  color: var(--fog);
  font-size: 0.9rem;
}

.game .d { display: none; }

/* The first game gets the big window */
.grid.has-lead > .item:first-child {
  grid-column: span 2;
  grid-row: span 2;
}

.has-lead > .item:first-child .tile {
  flex: 1;
  min-height: 0;
  aspect-ratio: auto;
}

.has-lead > .item:first-child h3 {
  font-family: var(--display);
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1.05;
  margin-top: 14px;
}

.has-lead > .item:first-child .d {
  display: block;
  max-width: 46ch;
  margin-top: 4px;
  color: var(--mist);
  opacity: 0.8;
  font-size: 0.98rem;
}

.has-lead > .item:first-child .cat { margin-top: 6px; }

/* Recently played: one smaller row above the games */
.shelf { margin-bottom: 40px; }

.shelf-title {
  color: var(--fog);
  font-size: 0.95rem;
  font-weight: 600;
}

.shelf-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  grid-template-rows: auto;
  grid-auto-rows: 0;
  row-gap: 0;
  margin: 12px -6px 0;
  padding: 6px;
  overflow: hidden;
}

.shelf-grid .tile { font-size: 2.4rem; }
.shelf-grid .game h3 { font-size: 0.95rem; margin-top: 8px; }
.shelf-grid .game .cat { display: none; }

.foot {
  padding-top: 20px;
  padding-bottom: 28px;
  border-top: 1px solid var(--line);
  color: var(--fog);
  font-size: 0.9rem;
  user-select: none;
}

/* ----- Game player ----- */
.player {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--deep);
}

.player-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--deep);
  border-bottom: 1px solid var(--line);
  color: var(--mist);
}

.player-title {
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
}

.player-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.player-actions a {
  padding: 7px 12px;
  text-decoration: none;
  color: var(--fog);
  font-size: 0.95rem;
}

.player-actions a:hover { color: var(--mist); }

.player-bar button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.player-bar button:hover { border-color: var(--fog); background: var(--pane); }

.player-bar #player-close {
  border-color: var(--lamp);
  background: var(--lamp);
  color: var(--lamp-ink);
  font-weight: 700;
}

.player-bar #player-close:hover { background: #f3c569; }

.stage { position: relative; flex: 1; min-height: 0; }
#player-frame { display: block; width: 100%; height: 100%; border: 0; background: var(--deep); }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: var(--deep);
  color: var(--mist);
  text-align: center;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.loading.done { opacity: 0; }

#loading-art {
  width: min(280px, 60vw);
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 4px;
  outline: 1px solid rgba(223, 232, 232, 0.09);
  outline-offset: -1px;
}

#loading-title {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

#loading-text { min-height: 1.5em; max-width: 36ch; color: var(--fog); font-size: 0.95rem; }

/* A short amber bar that sweeps across while the game loads */
.load-bar {
  position: relative;
  width: min(280px, 60vw);
  height: 3px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--line);
}

.load-bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  border-radius: 2px;
  background: var(--lamp);
  animation: sweep 1.1s ease-in-out infinite;
}

@keyframes sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

/* ----- Windows ----- */
dialog {
  width: min(480px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pane);
  color: var(--mist);
}

dialog::backdrop { background: rgba(8, 14, 18, 0.72); }

.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.dlg-head h2 {
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1;
}

#ext-close,
#editor-close,
#acc-close,
#lock,
#acc-create,
#acc-logout {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

#ext-close:hover,
#editor-close:hover,
#acc-close:hover,
#lock:hover,
#acc-create:hover,
#acc-logout:hover { border-color: var(--fog); background: var(--pane-hi); }

.list { border-top: 1px solid var(--line); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.row h3 { font-size: 1.05rem; }
.row p { color: var(--fog); font-size: 0.95rem; }

.button {
  flex-shrink: 0;
  padding: 8px 18px;
  border-radius: 4px;
  background: var(--lamp);
  color: var(--lamp-ink);
  font-weight: 700;
  text-decoration: none;
}

.button:hover { background: #f3c569; }

button.button {
  border: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button.button:disabled { opacity: 0.5; cursor: wait; }

.steps {
  margin: 18px 0 0;
  padding-left: 20px;
  color: var(--fog);
  font-size: 0.95rem;
}

.steps code {
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--deep);
  color: var(--mist);
}

.admin-box {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.admin-box h3 { margin-bottom: 10px; font-size: 1.05rem; }
.inline { display: flex; gap: 8px; }

label {
  display: block;
  margin-top: 12px;
  color: var(--fog);
  font-size: 0.95rem;
}

label input,
.inline input {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--deep);
  color: var(--mist);
  font: inherit;
}

label input:focus-visible,
.inline input:focus-visible { outline-offset: 0; border-color: var(--lamp); }

label input { margin-top: 4px; }
label input[type="file"] { height: auto; padding: 8px 12px; }

.conn { margin-top: 14px; color: var(--fog); font-size: 0.95rem; }
.conn summary { cursor: pointer; color: var(--mist); }
.note { margin-top: 8px; color: var(--fog); font-size: 0.9rem; }
.note.bad { color: var(--bad); }

/* Game editor */
.item { position: relative; }

.edit {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 10px;
  border: 0;
  border-radius: 3px;
  background: var(--deep);
  color: var(--mist);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.edit:hover { background: var(--lamp); color: var(--lamp-ink); }

#editor-form .button { margin-top: 12px; }

#remove {
  margin: 12px 0 0 8px;
  padding: 8px 18px;
  border: 1px solid var(--bad);
  border-radius: 4px;
  background: transparent;
  color: var(--bad);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#remove:hover { background: rgba(238, 139, 147, 0.12); }
#remove:disabled { opacity: 0.5; cursor: wait; }

.field { margin-top: 12px; }
.field-label { display: block; color: var(--fog); font-size: 0.95rem; }

.file-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.file-btn {
  display: inline-block;
  margin: 0;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--deep);
  color: var(--mist);
  font-size: 0.95rem;
  white-space: nowrap;
  cursor: pointer;
}

.file-btn:hover { border-color: var(--fog); }
.file-row:focus-within .file-btn { outline: 2px solid var(--lamp); outline-offset: 2px; }

.file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--mist);
  font-size: 0.95rem;
}

.file-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

#f-icon-preview {
  display: block;
  width: 96px;
  aspect-ratio: 16 / 10;
  margin-top: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* Log in window */
#acc-in .button,
#acc-create { margin: 14px 8px 0 0; }

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--fog);
  font-size: 0.9rem;
}

.or::before,
.or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

#acc-google {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin-top: 12px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

#acc-google:hover { border-color: var(--lamp); }

#acc-reset {
  display: block;
  margin-top: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--fog);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}

#acc-reset:hover { color: var(--mist); }

#acc-out p { margin-bottom: 4px; }
#acc-out button { margin-top: 12px; }

/* ----- Small screens: categories become a row you can swipe ----- */
@media (max-width: 900px) {
  main.wrap { grid-template-columns: minmax(0, 1fr); padding-top: 20px; }
  main.wrap > * { grid-column: 1 !important; }

  .chips {
    grid-row: auto;
    position: static;
    flex-direction: row;
    gap: 8px;
    margin-bottom: 26px;
    padding-bottom: 4px;
    overflow-x: auto;
  }

  .chip {
    flex: none;
    width: auto;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
  }

  .chip[aria-pressed="true"] { border-color: var(--lamp); }

  h1 { font-size: 2.2rem; white-space: nowrap; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  #search { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 22px 12px; }
  .shelf-grid { grid-template-columns: repeat(2, 1fr); }
  .tile { font-size: 2.4rem; }

  .grid.has-lead > .item:first-child { grid-row: auto; }
  .has-lead > .item:first-child .tile { flex: none; aspect-ratio: 16 / 9; }
  .has-lead > .item:first-child h3 { font-size: 1.7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .load-bar::after { animation-duration: 3s; }
}

/* ----- People and messages ----- */
#people {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

#people:hover { border-color: var(--fog); background: var(--pane); }

#people svg { width: 22px; height: 22px; }

#people-dialog { width: min(520px, calc(100% - 32px)); }

#people-close {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

#people-close:hover { border-color: var(--fog); background: var(--pane-hi); }

.people-list {
  max-height: min(46vh, 360px);
  margin-top: 12px;
  border-top: 1px solid var(--line);
  overflow-y: auto;
}

.person {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--mist);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.person:hover { color: var(--lamp); }

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

#chat-back {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--mist);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

#chat-back:hover { border-color: var(--fog); background: var(--pane-hi); }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: min(46vh, 340px);
  padding: 4px 2px;
  overflow-y: auto;
}

.msg {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--pane-hi);
  font-size: 0.95rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.msg.me {
  align-self: flex-end;
  background: var(--lamp);
  color: var(--lamp-ink);
  font-weight: 600;
}

.msg a {
  color: inherit;
  text-decoration: underline;
  font-weight: 700;
}

.msg .t {
  display: block;
  margin-top: 2px;
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.65;
}

#chat-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

#chat-text {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--deep);
  color: var(--mist);
  font: inherit;
}

#chat-text:focus-visible { outline-offset: 0; border-color: var(--lamp); }
#chat-form .button { padding: 8px 18px; }

/* A small note when a message arrives, even mid-game */
#toast {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  max-width: min(300px, calc(100vw - 32px));
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--lamp);
  border-radius: 6px;
  background: var(--pane);
  color: var(--mist);
  font-size: 0.9rem;
  line-height: 1.3;
  box-shadow: 0 10px 30px rgba(8, 14, 18, 0.45);
  cursor: pointer;
  animation: toast-in 0.18s ease-out;
}

#toast b { color: var(--lamp); font-weight: 600; }

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

/* ----- Which save wins? ----- */
#save-dialog { width: min(470px, calc(100% - 32px)); }

.save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 10px;
}

/* A game invite in chat: one clear Join button instead of a long link */
.chat-join {
  display: inline-block;
  margin: 4px 0 2px;
  padding: 7px 16px;
  border-radius: 4px;
  background: var(--lamp);
  color: #191307;
  font-weight: 700;
  text-decoration: none;
}
.chat-join:hover { filter: brightness(1.08); }

/* Online + unread marks in the People list */
.presence {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: rgba(223, 232, 232, 0.22);
}
.presence.on {
  background: #57d38c;
  box-shadow: 0 0 6px rgba(87, 211, 140, 0.55);
}
.person-name { flex: 1; min-width: 0; }
.unread {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--lamp);
}

/* The same yellow dot, on the People button in the header */
#people { position: relative; }
.header-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--lamp);
  box-shadow: 0 0 0 2px var(--deep);
}
