* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font: 13px/1.4 ui-sans-serif, system-ui, sans-serif;
  color: #d6d9d4;
  background: #1a1b17;
}

body { display: flex; flex-direction: column; height: 100dvh; }

button, .button {
  touch-action: manipulation;
  background: #21231e;
  border: 1px solid #3b3e37;
  color: #d6d9d4;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.button { display: flex; align-items: center; text-decoration: none; }

button:hover, .button:hover { background: #2a2c26; }
button:active, .button:active { background: #2a2c26; }

button:disabled {
  color: #555555;
  background: #21231e;
  cursor: not-allowed;
}

button.active,
button.primary {
  background: #a7c7a1;
  border-color: #a7c7a1;
  color: #1b1e18;
}

button.active:hover,
button.primary:hover { background: #bbd5b4; border-color: #bbd5b4; }

button.active:active,
button.primary:active { background: #8aa885; border-color: #8aa885; }

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(167, 199, 161, 0.4);
}

input, select {
  background: #1a1b17;
  border: 1px solid #3b3e37;
  color: inherit;
  padding: 6px 8px;
  border-radius: 6px;
  font: inherit;
  width: 100%;
}

input::placeholder { color: #9ba096; }
input:disabled, select:disabled { color: #555555; }

#auth {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  background: rgba(26, 27, 23, .78);
  z-index: 5;
}

.card {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow-y: auto;
  background: #21231e;
  border: 1px solid #3b3e37;
  border-radius: 12px;
  padding: 20px;
}

.card .close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  line-height: 1;
}

.card h1 {
  margin: 0 0 14px;
  font-size: 18px;
  color: #d8c6a3;
  padding-right: 42px;
  min-height: 34px;
}

#tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

#tabs button { flex: 1; padding: 6px 4px; }

.card section { display: grid; gap: 10px; }

label, .field {
  display: grid;
  gap: 4px;
  color: #9ba096;
}

.swatches { display: flex; gap: 6px; }

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
}

.swatch.active { border-color: #d6d9d4; }
.swatch.taken { opacity: .25; cursor: not-allowed; }
input.invalid { border-color: #c4645a; }

.error { margin: 0; color: #c4645a; }

#bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  background: #21231e;
  border-bottom: 1px solid #3b3e37;
  position: relative;
  z-index: 2;
}

.brand { flex-shrink: 0; font-weight: 700; color: #a7c7a1; white-space: nowrap; }
.spacer { flex: 1; min-width: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: 220px;
  gap: 7px;
  border: 1px solid #3b3e37;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
}

.chip i { flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; }
#team-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#menu { flex-shrink: 0; }
#menu summary {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid #3b3e37;
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
  touch-action: manipulation;
}
#menu summary::-webkit-details-marker { display: none; }
#menu[open] summary { background: #2a2c26; }
#menu summary:focus-visible { outline: 2px solid #a7c7a1; outline-offset: 2px; }
#menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: max(12px, env(safe-area-inset-right));
  width: min(250px, calc(100vw - 24px));
  max-height: calc(100dvh - 90px);
  overflow-y: auto;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #3b3e37;
  border-radius: 10px;
  background: #21231e;
  box-shadow: 0 8px 24px #0006;
}
#menu-panel button, #menu-panel .button { min-height: 44px; text-align: left; }
#clear, #admin-delete, #admin-ban { color: #e09a91; }
#admin-team-info { overflow-wrap: anywhere; font-size: 12px; }
#bans-list { display: grid; gap: 10px; }
.ban-help { margin: 0; color: #9ba096; }
.ban-entry { display: grid; gap: 8px; padding: 10px; border: 1px solid #3b3e37; border-radius: 6px; overflow-wrap: anywhere; }
.ban-entry p { margin: 0; color: #9ba096; }
.ban-entry button { min-height: 44px; }

#map-view { position: relative; flex: 1; min-height: 0; }
#map-controls {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid #3b3e37;
  border-radius: 10px;
  background: #21231e;
  box-shadow: 0 2px 10px #0005;
}
#tools { display: contents; }
#map-controls button { min-width: 54px; min-height: 44px; padding: 6px 10px; }

#brush-size-wrap {
  position: absolute;
  left: 50%;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 64px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(270px, calc(100% - 24px));
  padding: 8px 12px;
  border: 1px solid #3b3e37;
  border-radius: 10px;
  background: #21231e;
  color: #9ba096;
}
#brush-size { flex: 1; min-width: 0; height: 32px; accent-color: #a7c7a1; }
#brush-size-label { min-width: 26px; text-align: right; }

#zoom-controls {
  position: absolute;
  top: 12px;
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  gap: 4px;
}
#zoom-controls button { min-width: 44px; min-height: 44px; padding: 6px 8px; box-shadow: 0 2px 8px #0006; }
#zoom-in, #zoom-out { width: 44px; height: 44px; padding: 0; justify-self: end; }

#board {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#tooltip {
  position: fixed;
  z-index: 8;
  pointer-events: none;
  background: #21231e;
  border: 1px solid #3b3e37;
  border-radius: 6px;
  padding: 4px 8px;
  color: #d6d9d4;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
}

#toasts {
  position: fixed;
  top: 56px;
  right: 14px;
  display: grid;
  gap: 8px;
  width: 300px;
  z-index: 10;
}

.toast .actions { display: flex; gap: 8px; margin-top: 8px; }
.toast .actions button { flex: 1; padding: 4px 8px; }

.toast {
  background: #21231e;
  border: 1px solid #3b3e37;
  border-left: 3px solid #8fb6aa;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}


@media (max-width: 700px), (pointer: coarse) {
  button, input, select { min-height: 44px; }
  input, select { font-size: 16px; }
  #bar { gap: 8px; }
  #team-chip { max-width: 130px; padding: 4px 8px; }
  #auth { padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
  .card { padding: 16px; }
  .swatches { flex-wrap: wrap; }
  .swatch { width: 36px; height: 36px; min-height: 36px; }
  #toasts { top: auto; bottom: calc(140px + env(safe-area-inset-bottom)); right: 12px; width: min(300px, calc(100vw - 24px)); }
}
