:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #15211f;
  --muted: #64706d;
  --line: #d9e0de;
  --brand: #006c5b;
  --brand-dark: #004c42;
  --danger: #a13b2c;
  --ok: #087b5f;
  --warn: #9a6200;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 700;
}

button.secondary {
  background: #e7efed;
  color: var(--ink);
}

button.danger {
  background: var(--danger);
}

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.login-panel {
  width: min(420px, 100%);
  margin: 12vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.login-panel h1,
.topbar h1,
.remote-head h2,
.section-title h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel label {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

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

.login-panel button {
  width: 100%;
  margin-top: 14px;
}

.error {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

.topbar,
.section-title,
.remote-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.device-section,
.remote-panel {
  margin-top: 18px;
}

.section-title {
  margin-bottom: 10px;
}

#socketStatus {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.device-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.device-card h3 {
  margin: 0;
  font-size: 17px;
}

.device-card p {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.status.online {
  background: #e3f5ef;
  color: var(--ok);
}

.status.offline {
  background: #f2ece2;
  color: var(--warn);
}

.device-card button {
  width: 100%;
  margin-top: 12px;
}

.device-card button:disabled {
  background: #c9d0ce;
  color: #68706e;
}

.remote-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.remote-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.screen-wrap {
  position: relative;
  width: min(100%, 540px);
  aspect-ratio: 9 / 19.5;
  margin: 0 auto;
  background: #111;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

#screenImage {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

#screenEmpty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #c8d0ce;
  font-weight: 700;
}

@media (max-width: 640px) {
  .shell {
    padding: 12px;
  }

  .topbar,
  .remote-head {
    align-items: flex-start;
  }

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