:root {
  --bg: #14161f;
  --bg-panel: #1c1f2b;
  --bg-tile: #232735;
  --bg-tile-hover: #2c3143;
  --line: #333a4d;
  --text: #e6e8f0;
  --muted: #969cb3;
  --accent: #f2cf3a;
  --accent-dim: #8a7515;
  --good: #4bb04b;
  --bad: #d83b32;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: 17px;
  letter-spacing: 0.01em;
}

h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.room-code {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.room-code input {
  /* Three words, e.g. "shining-plucky-pyramid", need the room. */
  width: 160px;
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  padding: 4px 6px;
}

.btn {
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 5px 10px;
}

.btn:hover {
  background: var(--bg-tile-hover);
}

.btn-small {
  padding: 3px 8px;
  font-size: 12px;
}

.btn-danger:hover {
  border-color: var(--bad);
  color: #ffb4b0;
}

.pill {
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--muted);
}

.status {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.status-open {
  color: var(--good);
  border-color: #2f5f2f;
}

.status-connecting {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.status-closed {
  color: var(--bad);
  border-color: #6b2420;
}

.hint {
  margin: 0;
  padding: 8px 16px;
  background: #3a2d10;
  border-bottom: 1px solid var(--accent-dim);
  color: #f4dd8a;
  font-size: 13px;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 2fr) minmax(360px, 3fr);
  gap: 12px;
  padding: 12px 16px 72px;
  align-items: stretch;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

/* ---------- items ---------- */

.items {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.item-group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}

.group-count {
  font-size: 11px;
  letter-spacing: normal;
  text-transform: none;
}

/* A group heading that folds its contents away. */
.item-group-toggle {
  width: 100%;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 3px 4px;
  margin-left: -4px;
}

.item-group-toggle:hover,
.item-group-toggle:focus-visible {
  background: var(--bg-tile);
  color: var(--text);
  outline: none;
}

.group-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.group-caret {
  width: 9px;
  flex: none;
  font-size: 10px;
  line-height: 1;
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

@media (max-width: 560px) {
  .item-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.item {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  align-items: start;
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
}

.item.is-armed {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.item.is-found {
  border-color: #33543a;
}

.item-sprite {
  width: 44px;
  height: 44px;
  /* Real sprites are small and vary in shape, so scale them up without
     smoothing and keep their proportions inside the square. */
  image-rendering: pixelated;
  object-fit: contain;
  display: block;
}

.item.is-empty .item-sprite {
  opacity: 0.45;
  filter: grayscale(0.6);
}

.item-body {
  min-width: 0;
  /* Leave room for the pencil parked in the corner. */
  padding-right: 20px;
}

.item-name {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.25;
}

.item-count {
  margin-left: 5px;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
}

.item-count.is-full {
  color: var(--good);
}

.item-edit {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
}

.item-edit svg {
  width: 12px;
  height: 12px;
  display: block;
}

.item-edit:hover,
.item-edit:focus-visible {
  background: var(--bg-tile-hover);
  border-color: var(--accent-dim);
  color: var(--accent);
  outline: none;
}

.item-edit.is-full {
  opacity: 0.4;
}

.item.is-armed .item-edit {
  background: var(--accent);
  border-color: var(--accent);
  color: #201c05;
}

.item-locations {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.item-location {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  line-height: 1.3;
  color: #cfe6cf;
}

.item-location .loc-region {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.item-location .loc-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.loc-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0 2px;
}

.loc-remove:hover {
  color: var(--bad);
}

/* ---------- keys ---------- */

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

/* One dungeon per line: label, then big key, then the small-key box. */
.key-row {
  display: grid;
  grid-template-columns: 122px 1fr 1fr;
  gap: 6px;
  align-items: start;
}

.key-dungeon {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 10px;
  font-size: 11px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Keys get roomier tiles than the item grid — only two to a line. */
.key-row .item {
  grid-template-columns: 40px 1fr;
}

.key-row .item-sprite {
  width: 40px;
  height: 40px;
}

/* Hyrule Castle and Castle Tower have no big key; hold the column anyway. */
.key-row .item.is-small-only {
  grid-column: 3;
}

@media (max-width: 700px) {
  .key-row {
    grid-template-columns: 1fr 1fr;
  }

  .key-dungeon {
    grid-column: 1 / -1;
    padding-top: 4px;
  }

  .key-row .item.is-small-only {
    grid-column: 2;
  }
}

/* ---------- checks ---------- */

.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.search {
  flex: 1;
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  padding: 5px 8px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.region-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.region-chip {
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  padding: 2px 9px;
}

.region-chip[aria-pressed='true'] {
  color: #14161f;
  font-weight: 600;
}

/* The check list fills whatever height the item board sets, scrolling inside
   itself rather than leaving dead space beside a tall board. */
.panel-checks {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.checks {
  flex: 1;
  min-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}

.region-block + .region-block {
  margin-top: 12px;
}

.region-title {
  position: sticky;
  top: 0;
  z-index: 1;
  width: 100%;
  background: var(--bg-panel);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 5px 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.region-title:hover,
.region-title:focus-visible {
  background: var(--bg-tile);
  color: var(--text);
  outline: none;
}

.region-caret {
  width: 9px;
  flex: none;
  font-size: 10px;
  line-height: 1;
}

.region-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex: none;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 5px;
  margin-top: 5px;
}

.check {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 6px;
  align-items: center;
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  padding: 4px 6px;
  text-align: left;
}

.check:hover {
  background: var(--bg-tile-hover);
  border-color: var(--accent-dim);
}

.check-icon {
  width: 22px;
  height: 22px;
  image-rendering: pixelated;
  object-fit: contain;
  display: block;
}

.check-label {
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.check-holder {
  display: block;
  font-size: 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.check.is-used {
  border-color: #3d5540;
  background: #1f2a22;
}

.check.is-used .check-icon {
  opacity: 0.6;
}

/* Only meaningful while an item is armed, but harmless otherwise. */
.is-assigning .check:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ---------- assign bar ---------- */

.assign-bar {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent);
  color: #201c05;
  border-radius: 999px;
  padding: 7px 8px 7px 16px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  z-index: 10;
}

/* A class rule with display:flex would otherwise beat the [hidden] attribute. */
.assign-bar[hidden] {
  display: none;
}

.assign-bar .btn {
  background: rgba(0, 0, 0, 0.16);
  border-color: rgba(0, 0, 0, 0.3);
  color: #201c05;
  font-weight: 600;
}

/* ---------- home and changelog ---------- */

.page {
  display: flex;
  justify-content: center;
  padding: 48px 20px 64px;
}

.home {
  width: 100%;
  max-width: 640px;
}

.home-head h1 {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.home-head h1 span {
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.home-lede {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.home-start {
  margin: 32px 0;
  padding: 22px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.btn-big {
  width: 100%;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #201c05;
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 13px 16px;
}

.btn-big:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-big:disabled {
  cursor: default;
  opacity: 0.7;
}

.home-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.home-note.is-error {
  color: #ffb4b0;
}

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

.home-join label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.home-join-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg-tile);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
}

.home-join-row input:focus {
  border-color: var(--accent-dim);
  outline: none;
}

.home-how h2,
.home-about h2 {
  margin-bottom: 10px;
}

.home-about {
  margin-top: 32px;
}

.home-about p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.home-about a,
.release a {
  color: var(--accent);
  text-decoration: none;
}

.home-about a:hover,
.release a:hover {
  text-decoration: underline;
}

.home-foot a + a {
  margin-left: 14px;
}

.home-how ol {
  margin: 0;
  padding-left: 20px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

/* Each changelog entry, once there are any. */
.release {
  margin: 32px 0 28px;
}

.release h2 {
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: none;
}

.release ul {
  margin: 8px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.home-foot {
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.home-foot a {
  color: var(--muted);
  text-decoration: none;
}

.home-foot a:hover {
  color: var(--accent);
}

.brand-home {
  color: inherit;
  text-decoration: none;
}

.brand-home:hover {
  color: var(--accent);
}
