* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --faint: #484f58;
  --accent: #f97316;
  --accent-strong: #ea580c;
  --ok: #238636;
  --info: #58a6ff;
  --warn: #d29922;
  --bad: #da3633;
  --mono: "SF Mono", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; color: inherit; }

button {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-strong); }
button.danger:hover:not(:disabled) { border-color: var(--bad); color: #ff7b72; }

input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Landing page */

.home { max-width: 760px; margin: 0 auto; padding: 72px 24px 48px; }
.brand { text-align: center; margin-bottom: 40px; }
.brand h1 { font-size: 36px; font-weight: 700; letter-spacing: -1px; color: var(--accent); }
.brand p { color: var(--muted); font-size: 15px; margin-top: 8px; }

.home h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 32px 0 10px;
}
.grid { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--accent); }
.card-body { flex: 1; min-width: 0; }
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 3px; }
.card p { font-size: 13px; color: var(--muted); line-height: 1.4; }
.card-meta { font-size: 11px; color: var(--faint); margin-top: 5px; }
.card button { flex-shrink: 0; padding: 8px 18px; font-size: 13px; }

.custom { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.custom label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.custom .wide { grid-column: 1 / -1; }
.custom .row { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.custom .error { color: #ff7b72; font-size: 12px; }

.footer { text-align: center; color: var(--faint); font-size: 12px; margin-top: 48px; line-height: 1.6; }
.footer a { color: var(--muted); }

/* Machine page */

body.machine { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

header {
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
header a { color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600; }
header a:hover { color: var(--accent); }
#name { font-size: 13px; font-weight: 600; }
#status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bad);
  color: #fff;
  white-space: nowrap;
}
#status[data-state="running"] { background: var(--ok); }
#status[data-state="restoring"], #status[data-state="optimizing"] { background: var(--info); color: #000; }
#status[data-state="starting"], #status[data-state="saving"] { background: var(--warn); color: #000; }
#status[data-state="stopped"] { background: var(--faint); }
#speed { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.spacer { flex: 1; }

main { flex: 1; display: flex; min-height: 0; }
#display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  min-width: 0;
  position: relative;
}
#screen {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  background: #000;
  outline: none;
}
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(13, 17, 23, 0.82);
  text-align: center;
  padding: 24px;
}
#overlay[hidden] { display: none; }
#overlay-title { font-size: 16px; font-weight: 600; }
#overlay-detail { font-size: 13px; color: var(--muted); max-width: 520px; line-height: 1.5; }
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

aside {
  width: 250px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
}
aside[hidden] { display: none; }
aside h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 12px 0 6px;
}
aside h3:first-child { margin-top: 0; }
aside div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--muted); }
aside div span:last-child { color: var(--text); }

#serial {
  flex-shrink: 0;
  height: 190px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
}
#serial[hidden] { display: none; }
#serial-output { flex: 1; overflow-y: auto; padding: 8px 12px; white-space: pre-wrap; word-break: break-all; color: #c9d1d9; }
#serial-input { border: none; border-top: 1px solid var(--border); border-radius: 0; font-family: var(--mono); font-size: 12px; }

@media (max-width: 720px) {
  .home { padding-top: 40px; }
  .card { flex-wrap: wrap; }
  .custom { grid-template-columns: 1fr; }
  aside { position: absolute; right: 0; top: 0; bottom: 0; z-index: 2; }
}
