:root {
  --bg: #0f1218;
  --panel: #181d26;
  --panel-soft: #202736;
  --ink: #f6f8fb;
  --muted: #a9b4c6;
  --line: #343d4f;
  --accent: #2dd4bf;
  --accent-2: #7dd3fc;
  --pulse: #fb7185;
  --ok: #86efac;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  min-height: 48px;
  padding: 0.75rem 0.9rem;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.5;
}

.button-link {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: inline-flex;
  min-height: 48px;
  padding: 0.75rem 0.9rem;
  text-decoration: none;
}

button:active {
  transform: scale(0.985);
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #041313;
  font-weight: 900;
}

.topbar {
  display: grid;
  gap: 0.55rem;
  padding: max(0.55rem, env(safe-area-inset-top)) 0.85rem 0.65rem;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 18, 24, 0.94);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.brand-line {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
}

.brand-title {
  min-width: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.05;
}

h2 {
  margin-bottom: 0.65rem;
  font-size: 1.1rem;
}

.eyebrow,
.control-title {
  margin-bottom: 0.25rem;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.session {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.9rem;
}

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 0.85rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
}

.notice,
.message,
.auth-card,
.measure-card,
.history,
.access-card,
.admin {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.notice,
.message {
  width: min(760px, calc(100% - 1.7rem));
  margin: 0.85rem auto 0;
  padding: 0.8rem 1rem;
}

.notice span {
  display: block;
  color: var(--muted);
  margin-top: 0.3rem;
}

.auth-card,
.measure-card,
.history,
.access-card,
.admin {
  padding: 1rem;
}

.auth-card {
  margin-top: 1rem;
}

.workspace {
  display: grid;
  gap: 0.85rem;
}

.measure-card {
  display: grid;
  gap: 1rem;
}

.dog-row label {
  max-width: 100%;
}

.choice-block {
  display: grid;
  gap: 0.45rem;
}

.big-switch,
.segmented,
.mode-grid,
.location-grid {
  display: grid;
  gap: 0.45rem;
}

.brand-title .eyebrow {
  display: block;
  margin-bottom: 0.1rem;
  font-size: 0.62rem;
}

.version-link {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.connection-status {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: right;
}

.top-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.top-tab {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  display: inline-flex;
  justify-content: center;
  min-height: 40px;
  padding: 0.5rem 0.65rem;
  text-align: center;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 900;
}

.big-switch {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mode-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.location-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.big-switch button,
.segmented button,
.mode-grid button,
.location-grid button {
  font-weight: 850;
}

.is-active {
  border-color: var(--accent);
  background: #123b3a;
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.35);
}

.meter-stage {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121721;
}

.meter-meta,
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  color: var(--muted);
}

.meter-meta {
  display: grid;
  gap: 0.25rem;
  justify-content: stretch;
  text-align: center;
  min-height: 5.75rem;
  align-content: center;
}

#meterStatus {
  color: var(--ink);
  font-size: clamp(2.1rem, 12vw, 4.4rem);
  font-weight: 1000;
  line-height: 1;
}

#meterCount {
  color: var(--accent-2);
  font-size: 1.05rem;
  font-weight: 900;
}

.section-head {
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.section-head h2 {
  margin: 0;
}

.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.tap-button {
  width: 100%;
  min-height: min(46vh, 18rem);
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: #0f3736;
  color: var(--accent);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.6rem;
  font-size: clamp(1.65rem, 8vw, 3rem);
  font-weight: 1000;
  position: relative;
  overflow: hidden;
}

.tap-button small {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

.tap-button.tap-hit {
  animation: tap-hit 180ms ease-out;
}

.tap-button.tap-hit::after {
  animation: tap-ring 320ms ease-out;
  border: 3px solid var(--ok);
  border-radius: 8px;
  content: "";
  inset: 0.35rem;
  position: absolute;
}

.tap-button:disabled {
  opacity: 1;
  border-color: var(--line);
  background: #18202d;
  color: var(--muted);
}

.secondary-action {
  justify-self: center;
  min-width: 12rem;
}

@keyframes tap-hit {
  0% { transform: scale(0.98); background: #145c57; }
  55% { transform: scale(1.015); background: #168476; }
  100% { transform: scale(1); background: #0f3736; }
}

@keyframes tap-ring {
  0% { opacity: 1; transform: scale(0.82); }
  100% { opacity: 0; transform: scale(1.08); }
}

.result {
  display: block;
  min-height: 3.8rem;
  color: var(--ink);
  font-size: clamp(2.15rem, 11vw, 4.2rem);
  font-weight: 1000;
  line-height: 1;
  text-align: center;
}

.save-panel,
.inline-form {
  display: grid;
  gap: 0.85rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.context-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: end;
  gap: 0.65rem;
}

.icon-button {
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121721;
  color: var(--ink);
  min-height: 48px;
  padding: 0.75rem;
}

textarea {
  resize: vertical;
}

.muted {
  color: var(--muted);
}

.inline-form {
  grid-template-columns: 1fr 1fr auto;
}

.entries,
.user-list {
  display: grid;
  gap: 0.65rem;
}

.entry,
.user-row {
  display: grid;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem;
  background: var(--panel-soft);
}

.entry.is-editing {
  border-color: var(--accent);
}

.entry-toggle {
  display: grid;
  gap: 0.65rem;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.entry-main {
  display: grid;
  gap: 0.65rem;
}

.entry-main strong,
.entry-main .muted {
  display: block;
}

.numbers {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.entry-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}

.entry-editor-wide {
  grid-column: 1 / -1;
}

.chip {
  border-radius: 999px;
  background: #123b3a;
  color: var(--accent);
  padding: 0.28rem 0.58rem;
  font-size: 0.88rem;
  font-weight: 900;
}

.setup-link {
  overflow-wrap: anywhere;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 0.75rem;
  background: #123b3a;
}

.delete-entry {
  border-color: #7f1d1d;
  background: #3b1116;
  color: #fda4af;
  min-height: 36px;
  padding: 0.35rem 0.6rem;
}

.entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.dog-edit {
  gap: 0.8rem;
}

footer {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .brand-line {
    align-items: start;
  }

  .form-grid,
  .inline-form,
  .location-grid,
  .entry-editor {
    grid-template-columns: 1fr;
  }

  .measure-card,
  .history,
  .access-card,
  .admin {
    padding: 0.85rem;
  }
}
.account-card {
  display: grid;
  gap: 0.85rem;
}
