:root {
  --bg: #1b1714;
  --surface: #2a2420;
  --surface-hi: #3a312b;
  --border: #4a3f37;
  --text: #f0e6d8;
  --muted: #a8998a;
  --accent: #c9a14a;
  --character: #6fa8dc;
  --monster: #d9534f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}

h1 { font-size: 1.5rem; margin: 8px 0 16px; color: var(--accent); }
h2 { font-size: 1.1rem; margin: 24px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

.combobox { position: relative; }

#search {
  width: 100%;
  /* 16px+ prevents iOS zoom on focus */
  font-size: 1.05rem;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
#search:focus { border-color: var(--accent); }

.suggestions {
  position: absolute;
  z-index: 10;
  left: 0; right: 0;
  top: calc(100% + 4px);
  margin: 0; padding: 4px 0;
  list-style: none;
  max-height: 50vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

.suggestions li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 16px;
  cursor: pointer;
}
.suggestions li[aria-selected="true"],
.suggestions li:hover { background: var(--surface-hi); }
.suggestions li.no-match { color: var(--muted); cursor: default; }
.suggestions li.no-match:hover { background: none; }
.suggestions mark { background: none; color: var(--accent); font-weight: 600; }

.tag {
  font-size: .75rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  flex-shrink: 0;
}
.tag.character { color: var(--character); }
.tag.monster { color: var(--monster); }

.status { min-height: 1.2em; margin: 6px 2px 0; font-size: .875rem; color: var(--muted); }

.roster { list-style: none; margin: 0; padding: 0; }
.roster li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 6px 6px 6px 14px;
  margin-bottom: 6px;
  background: var(--surface);
  border-left: 4px solid var(--border);
  border-radius: 8px;
}
.roster li.character { border-left-color: var(--character); }
.roster li.monster { border-left-color: var(--monster); }
.roster li[aria-current="true"] {
  background: var(--surface-hi);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.roster .name {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
}
.roster li[aria-current="true"] .name::before {
  content: "▶";
  color: var(--accent);
  font-size: .8rem;
}

.initiative {
  width: 3.5em;
  /* 16px+ prevents iOS zoom on focus */
  font-size: 1.1rem;
  padding: 8px 4px;
  text-align: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  flex-shrink: 0;
}
.initiative:focus { border-color: var(--accent); }
.initiative[aria-invalid="true"] { border-color: var(--monster); }

.turn-controls {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px 8px;
  padding: 8px 16px;
  background: var(--bg);
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 8px;
}
.page-header h1 { margin: 0; }
.page-header button { flex-shrink: 0; }

.round {
  margin: 0 2px 8px;
  font-size: 1.25rem;
  font-weight: 600;
}
#round-number { color: var(--accent); }

.turn-buttons { display: flex; gap: 8px; }
.turn-buttons button { padding-left: 8px; padding-right: 8px; }
.turn-buttons button { flex: 1; }
.status.error { color: var(--monster); }

.dialog-help { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }

/* Lives inside a dialog, which would clip an absolutely positioned drop-down. */
.suggestions.inline {
  position: static;
  margin-top: 4px;
  max-height: 40vh;
  box-shadow: none;
}

.choice-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.choice-list label {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--character);
  border-radius: 8px;
  cursor: pointer;
}
.choice-list label.monster { border-left-color: var(--monster); }
.choice-list label:has(input:checked) { border-color: var(--accent); background: var(--surface-hi); }
.choice-list input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.choice-list .name { flex: 1; }
.choice-list .init { color: var(--muted); font-variant-numeric: tabular-nums; }

.opener-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.opener-line strong { color: var(--accent); }
.opener-line button { flex-shrink: 0; }
.reveal-new { width: 100%; margin-top: 8px; }
.reveal-list { margin-top: 12px; }
.reveal-list li { background: var(--bg); border-left-color: var(--monster); }
.reveal-list .name { flex-direction: column; align-items: flex-start; gap: 2px; }
.note { font-size: .8rem; color: var(--muted); }
.initiative[readonly] { color: var(--muted); border-style: dashed; }
.initiative[hidden] { display: none; }
.tie-list { list-style: none; margin: 0 0 16px; padding: 0; }
.tie-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 4px 4px 4px 12px;
  margin-bottom: 6px;
  background: var(--bg);
  border-left: 4px solid var(--border);
  border-radius: 8px;
}
.tie-list li.character { border-left-color: var(--character); }
.tie-list li.monster { border-left-color: var(--monster); }
.tie-list .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.move {
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.move:disabled { color: var(--border); cursor: default; }

.remove {
  width: 44px; height: 44px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}
.remove:hover, .remove:focus-visible { background: var(--surface-hi); color: var(--text); }

.empty { color: var(--muted); font-style: italic; margin: 4px 2px; }
.empty[hidden] { display: none; }

.add-new {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.add-new button { flex: 1; }

button.primary,
button.secondary {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
}
button.primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
button.secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
button.secondary:hover { background: var(--surface-hi); }
button:disabled,
button:disabled:hover {
  border-color: var(--border);
  background: var(--surface-hi);
  color: var(--muted);
  cursor: not-allowed;
}

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 14px; color: var(--accent); text-transform: none; letter-spacing: 0; font-size: 1.15rem; }

#add-name,
#reveal-search {
  width: 100%;
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
#add-name:focus,
#reveal-search:focus { border-color: var(--accent); }
#add-name[aria-invalid="true"] { border-color: var(--monster); }

.field-error { min-height: 1.2em; margin: 6px 2px 12px; font-size: .875rem; color: var(--monster); }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button { min-width: 96px; }

.login { padding-top: 15vh; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { color: var(--muted); font-size: .9rem; }
.login-form input {
  width: 100%;
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.login-form input:focus { border-color: var(--accent); }
.login-form input[aria-invalid="true"] { border-color: var(--monster); }
.login-form .field-error { margin: 0 2px 4px; }

.logout { margin-top: 32px; text-align: center; }
button.link {
  min-height: 44px;
  padding: 8px 16px;
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: .9rem;
  text-decoration: underline;
  cursor: pointer;
}
