:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #17212b;
  --muted: #5b6875;
  --line: #dde3e9;
  --primary: #0b6bcb;
  --primary-dark: #0957a6;
  --ok: #1a7f4b;
  --error: #b3261e;
  --radius: 14px;
  --vh: 1vh;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.05rem; }
.powered { color: var(--muted); font-size: 0.85rem; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 20px;
}

h1 { font-size: 1.5rem; margin: 0 0 12px; line-height: 1.25; }
.lead { font-size: 1.05rem; margin: 0 0 16px; }
.tips { margin: 0 0 16px; padding-left: 20px; }
.tips li { margin-bottom: 6px; }
.note { color: var(--muted); font-size: 0.9rem; margin: 0 0 20px; }

.alert {
  background: #fdecea;
  color: var(--error);
  border: 1px solid #f5c2bd;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--text); color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--line); }
.btn-large { width: 100%; font-size: 1.15rem; min-height: 56px; }

/* Measuring */
#screen-measure {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.canvas-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  height: calc(var(--vh) * 100 - 220px);
  min-height: 360px;
}
#mxcanvas {
  aspect-ratio: 480 / 894;
  height: 100%;
  max-width: 100%;
}
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  font-weight: 600;
}
.measure-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "progress progress" "status cancel";
  gap: 8px 12px;
  align-items: center;
}
.progress {
  grid-area: progress;
  height: 8px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width 0.4s ease;
}
.status { grid-area: status; margin: 0; font-weight: 600; }
#btn-cancel { grid-area: cancel; }

/* Results */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.tile-label { color: var(--muted); font-size: 0.9rem; }
.tile-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.tile-unit { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.tile-empty .tile-value { color: var(--muted); }

.disclaimer { color: var(--muted); font-size: 0.85rem; margin: 0 0 20px; }

.email-form {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}
.email-form label { display: block; font-weight: 600; margin-bottom: 8px; }
.email-row { display: flex; gap: 8px; flex-wrap: wrap; }
.email-row input {
  flex: 1 1 220px;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.email-row input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.email-status { min-height: 1.5em; margin: 8px 0 0; font-size: 0.95rem; }
.email-status.ok { color: var(--ok); }
.email-status.error { color: var(--error); }

.actions {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 18px;
}

@media (max-width: 480px) {
  .card { padding: 20px 16px; }
  .actions .btn { flex: 1 1 auto; }
}
