:root {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --text: #14213d;
  --muted: #64748b;
  --line: #d8e0ea;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --danger: #d71920;
  --danger-dark: #9f1117;
  --disabled: #cbd5e1;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

button,
select,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(100%, 420px);
}

.login-panel,
.control-section,
.sensor-card,
.message-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  padding: 32px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 34px;
}

.login-panel p {
  margin: 0 0 28px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form label {
  font-weight: 700;
}

.login-form input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
}

.login-form button,
.control-button,
.ghost-button,
.drive-button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.login-form button {
  min-height: 48px;
  background: var(--brand);
  color: #fff;
}

.form-error {
  color: var(--danger);
  font-weight: 700;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.ghost-button {
  min-height: 40px;
  padding: 0 16px;
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--line);
}

.dashboard {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 24px clamp(14px, 4vw, 32px) 40px;
  display: grid;
  gap: 18px;
}

.status-row,
.sensor-grid,
.accessory-grid {
  display: grid;
  gap: 12px;
}

.status-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.status-badge,
.socket-status {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 14px;
  font-weight: 700;
}

.status-badge.online {
  background: #dcfce7;
  color: #166534;
}

.status-badge.offline {
  background: #fee2e2;
  color: #991b1b;
}

.socket-status {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
}

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

.sensor-card {
  padding: 18px;
}

.sensor-card span,
.message-panel span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.sensor-card strong {
  font-size: 26px;
}

.control-section {
  padding: 18px;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.section-heading p {
  margin: 0;
  color: var(--muted);
}

.drive-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  grid-template-areas:
    ". forward ."
    "left stop right"
    ". backward .";
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.drive-button {
  min-height: 72px;
  padding: 0 10px;
  background: var(--brand);
  color: #fff;
  font-size: 18px;
}

.drive-button:active,
.control-button:active {
  transform: translateY(1px);
}

.drive-button.forward {
  grid-area: forward;
}

.drive-button.left {
  grid-area: left;
}

.drive-button.right {
  grid-area: right;
}

.drive-button.backward {
  grid-area: backward;
}

.stop-button {
  grid-area: stop;
  background: var(--danger);
  font-size: 16px;
}

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

.control-button,
.select-control select {
  min-height: 52px;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
}

.control-button {
  background: var(--brand);
  color: #fff;
}

.control-button[aria-pressed="true"] {
  background: var(--brand-dark);
}

.select-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.select-control select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 700;
}

.message-panel {
  padding: 16px 18px;
}

.message-panel strong {
  display: block;
  min-height: 24px;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  background: var(--disabled);
  color: #64748b;
  transform: none;
}

@media (max-width: 700px) {
  .topbar {
    align-items: flex-start;
  }

  .status-row,
  .sensor-grid,
  .accessory-grid {
    grid-template-columns: 1fr;
  }

  .drive-pad {
    grid-template-columns: repeat(3, minmax(64px, 1fr));
  }

  .drive-button {
    min-height: 64px;
    font-size: 16px;
  }
}
