:root {
  /* preto puro: bate com o relógio de referência e poupa painéis OLED */
  --bg: #000;
  --card: #1c1c1c;
  --card-border: rgba(255, 255, 255, .06);
  --text: #d2d2d2;
  --muted: #78828c;
  --accent: #34d399;
  --danger: #f87171;
  --sheet: #161616;
  --field: #232323;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.light {
  --bg: #eceef1;
  --card: #fbfbfc;
  --card-border: rgba(0, 0, 0, .08);
  --text: #323232;
  --muted: #787878;
  --sheet: #ffffff;
  --field: #eceef1;
}

* { box-sizing: border-box; }

/* as folhas usam display:flex/grid — sem isto o atributo hidden não faz nada */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: calc(var(--safe-top) + 8px) 10px calc(var(--safe-bottom) + 10px);
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 6px 8px;
  transition: opacity .35s ease;
}

body.dock .topbar { opacity: 0; pointer-events: none; }
body.dock.awake-hint .topbar { opacity: 1; pointer-events: auto; }

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
  min-width: 0;
}

.status span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.dot.ok { background: var(--accent); }
.dot.stale { background: #fbbf24; }
.dot.err { background: var(--danger); }
.dot.loading { animation: pulse 1.1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .25; } }

.actions { display: flex; gap: 4px; flex: none; }

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  cursor: pointer;
}

.icon-btn:active { background: var(--field); }
.icon-btn.on { color: var(--accent); }

/* ---------- palco / cartão ---------- */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.card {
  width: 100%;
  max-width: 760px;
  max-height: 100%;
  min-width: 0; /* sem isto o conteúdo empurra o cartão para fora do ecrã */
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 6px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, .38);
  overflow: hidden;
}

body.light .card { box-shadow: 0 12px 32px rgba(0, 0, 0, .12); }

.gauges {
  display: grid;
  grid-template-columns: 1fr .82fr 1fr;
  align-items: stretch;
  min-width: 0;
  /* altura fixa: os medidores já limitam o raio pela largura, portanto crescer
     em altura só criaria banda vazia */
  height: clamp(190px, 52vh, 340px);
}

.gauge-slot { min-width: 0; position: relative; }
.gauge-slot canvas { display: block; width: 100%; height: 100%; }

/* ---------- relógio flip ---------- */
.clock {
  /* tamanho do dígito — nome próprio (não "--card") pra não colidir com a
     cor de fundo dos cartões (--card em :root), já que esta variável é
     redefinida aqui e herdada por todos os elementos dentro de .clock */
  /* o par de cartões ocupa 2 × fcard + gap ≈ 2.095 × fcard, então fcard nunca
     pode passar de ~47% da largura disponível. Medimos pelo contêiner (cqw) e
     não pela viewport: no modo lado a lado o relógio vive numa coluna estreita
     e o vw fazia os cartões transbordarem por cima dos medidores. */
  container-type: inline-size;
  --fcard: min(46cqw, 62vh);
  --gap: calc(var(--fcard) * 0.095);
  /* 0.89 × altura do cartão dá a mesma mancha do relógio de referência com
     fontes de cap-height ~0.72em (SF Pro Rounded, Nunito) */
  --digit: calc(var(--fcard) * 0.89);
  --label: calc(var(--fcard) * 0.075);
  --seconds: calc(var(--fcard) * 0.085);
  --radius: calc(var(--fcard) * 0.11);
  --flip-ms: 320ms;

  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--fcard) * 0.065);
  width: 100%;
  flex: none;
  min-width: 0;
}

/* cabeçalho fora dos cartões: data à esquerda, dia da semana à direita,
   alinhado com a largura do par de dígitos abaixo */
.clock-head {
  display: flex;
  width: calc(var(--fcard) * 2 + var(--gap));
  gap: var(--gap);
  font-size: var(--label);
  font-weight: 700;
  color: #b0b0b0;
  letter-spacing: .01em;
  white-space: nowrap;
}

.clock-head span:first-child { text-align: left; }
.clock-head span:last-child { text-align: right; }
body.light .clock-head { color: #4a4a4a; }

.clock-face { position: relative; }

.clock-row {
  position: relative;
  display: flex;
  gap: var(--gap);
}

/* o vinco atravessa os dois cartões e o intervalo entre eles, como no original */
.clock-row::after {
  content: "";
  position: absolute;
  left: calc(var(--fcard) * -0.02);
  right: calc(var(--fcard) * -0.02);
  top: 50%;
  height: max(2px, calc(var(--fcard) * 0.0035));
  background: #000;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 3;
}

.flip {
  position: relative;
  width: var(--fcard);
  height: calc(var(--fcard) * 1.01);
  border-radius: var(--radius);
  background: #131313;
  overflow: hidden;
  perspective: calc(var(--fcard) * 2.2);
  font-family: ui-rounded, "SF Pro Rounded", "Varela Round", "Nunito",
               "Hiragino Maru Gothic ProN", system-ui, sans-serif;
}

body.light .flip { background: #e6e7ea; }
body.light .clock-row::after { background: var(--bg); }

/* metades fixas: cada uma corta o mesmo texto, alinhado no centro do cartão */
.face {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
}

.face-top { top: 0; }
.face-bottom { bottom: 0; }

.face .val,
.flap .val {
  position: absolute;
  left: 0;
  width: 100%;
  height: calc(var(--fcard) * 1.01);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--digit);
  font-weight: 800;
  letter-spacing: calc(var(--fcard) * -0.022);
  line-height: 1;
  color: #b0b0b0;
  font-variant-numeric: tabular-nums;
  /* centra pela mancha do algarismo, não pela caixa da fonte (que inclui o
     espaço do descendente e deixava os dígitos assentes baixo) */
  transform: translateY(-4.5%);
}

body.light .face .val,
body.light .flap .val { color: #4a4a4a; }

.face-top .val, .flap-front .val { top: 0; }
.face-bottom .val, .flap-back .val { bottom: 0; }

/* pás animadas */
.flap {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  background: #131313;
  backface-visibility: hidden;
  z-index: 2;
  display: none;
}

body.light .flap { background: #e6e7ea; }

.flap-front { top: 0; transform-origin: bottom center; }
.flap-back { bottom: 0; transform-origin: top center; transform: rotateX(90deg); }

.flip.flipping .flap-front {
  display: block;
  animation: flap-front-out var(--flip-ms) ease-in forwards;
}

.flip.flipping .flap-back {
  display: block;
  animation: flap-back-in var(--flip-ms) ease-out var(--flip-ms) forwards;
}

@keyframes flap-front-out {
  from { transform: rotateX(0deg); }
  to { transform: rotateX(-90deg); }
}

@keyframes flap-back-in {
  from { transform: rotateX(90deg); }
  to { transform: rotateX(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .flip.flipping .flap-front, .flip.flipping .flap-back { animation: none; display: none; }
}

/* segundos: canto inferior direito do conjunto do relógio (não mais preso
   só ao cartão dos minutos) */
.clock-seconds {
  position: absolute;
  z-index: 4;
  right: calc(var(--fcard) * 0.055);
  bottom: calc(var(--fcard) * 0.03);
  font-size: var(--seconds);
  font-weight: 700;
  color: #b0b0b0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

body.light .clock-seconds { color: #4a4a4a; }
body[data-seconds="off"] .clock-seconds { display: none; }

/* ---------- vistas ---------- */
body[data-view="clock"] .card { display: none; }
body[data-view="gauges"] .clock { display: none; }

/* modo combinado: relógio e medidores lado a lado, cada um na sua "moldura",
   com o relógio ligeiramente maior — como no dispositivo de referência */
body[data-view="both"] .stage {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

body[data-view="both"] .clock {
  --fcard: min(46cqw, 62vh);
  flex: 1 1 auto;
  min-width: 0;
  max-width: 900px;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: calc(var(--fcard) * 0.06) calc(var(--fcard) * 0.07);
  box-shadow: 0 18px 46px rgba(0, 0, 0, .38);
}

body[data-view="both"].light .clock { box-shadow: 0 12px 32px rgba(0, 0, 0, .12); }

/* medidores numa coluna estreita à direita: relógio manda no espaço */
body[data-view="both"] .card {
  flex: 0 0 auto;
  min-width: 0;
  width: clamp(190px, 23vw, 275px);
  max-width: none;
}

body[data-view="both"] .gauges {
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, 1fr);
  height: clamp(340px, 86vh, 700px);
}

/* o Timer volta para o meio da coluna (a regra de retrato o joga para baixo) */
body[data-view="both"] .gauge-slot.timer {
  grid-column: 1;
  grid-row: 2;
}

body[data-view="both"] .gauge-slot.timer canvas { width: 100%; }

/* telas estreitas/retrato: lado a lado fica apertado demais — volta a empilhar */
@media (max-width: 760px), (orientation: portrait) {
  body[data-view="both"] .stage {
    flex-direction: column;
    gap: 12px;
  }
  body[data-view="both"] .clock {
    --fcard: min(46cqw, 26vh);
    width: 100%;
    max-width: 640px;
  }
  body[data-view="both"] .card { max-width: 640px; }
  body[data-view="both"] .gauges { height: clamp(190px, 42vh, 320px); }
}

/* proteção de ecrã: deslocamento lento anti-burn-in + escurecer em repouso */
.stage { transition: opacity 1.2s ease, transform 3s ease-in-out; }
body.dimmed .stage { opacity: .5; }

/* ---------- linhas extra ---------- */
.extras {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 8px 2px;
  border-top: 1px solid var(--card-border);
  margin-top: 4px;
}

.extra-row {
  display: grid;
  grid-template-columns: auto minmax(30px, 1fr) auto auto;
  align-items: center;
  gap: 9px;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
}

.extra-label { font-weight: 600; color: var(--text); white-space: nowrap; }

.bar {
  min-width: 0;
  height: 5px;
  border-radius: 99px;
  background: rgba(128, 128, 128, .22);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #34d399, #059669);
  transition: width .4s ease;
}

.extra-value { font-variant-numeric: tabular-nums; color: var(--text); }
.extra-reset { font-variant-numeric: tabular-nums; }

.footer {
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  padding: 4px 0 2px;
  min-height: 16px;
}

body.dock .footer { opacity: .55; }

/* ---------- folhas (setup / definições) ---------- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  overflow-y: auto;
  user-select: text;
}

.sheet-inner {
  width: 100%;
  max-width: 560px;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(var(--safe-bottom) + 22px);
  border: 1px solid var(--card-border);
  border-bottom: 0;
}

@media (min-width: 620px) {
  .sheet { align-items: center; }
  .sheet-inner { border-radius: 20px; border-bottom: 1px solid var(--card-border); }
}

.sheet h1 { font-size: 19px; margin: 0 0 10px; color: var(--text); }
.lead { font-size: 13.5px; color: var(--muted); margin: 0 0 14px; }

.steps { margin: 0 0 14px; padding-left: 18px; font-size: 13px; color: var(--muted); }
.steps li { margin-bottom: 8px; }

code {
  display: inline-block;
  background: var(--field);
  border-radius: 6px;
  padding: 2px 6px;
  font: 12px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace;
  color: var(--text);
  word-break: break-all;
}

.hint { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; }

.option {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.option h2 {
  font-size: 13.5px;
  margin: 0 0 4px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #062b20;
  background: var(--accent);
  border-radius: 99px;
  padding: 2px 7px;
}

.option.highlight {
  border-color: rgba(52, 211, 153, .38);
  background: rgba(52, 211, 153, .06);
}

/* bloco de colar: a ação principal da tela */
.paste-block { margin: 14px 0 12px; }

button.wide { width: 100%; flex: none; font-size: 15px; padding: 14px; }

.paste-block .hint { text-align: center; margin: 8px 0 10px; }

.help {
  border-top: 1px solid var(--card-border);
  padding-top: 12px;
  margin-top: 4px;
}

.help summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 0;
  list-style: revert;
}

.help h3 {
  font-size: 13px;
  margin: 14px 0 6px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

kbd {
  display: inline-block;
  background: var(--field);
  border: 1px solid var(--card-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  font: 600 11px/1.5 ui-monospace, Consolas, monospace;
  color: var(--text);
}

.copy-path {
  display: inline-block;
  margin: 4px 6px 2px 0;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 11.5px;
  cursor: pointer;
}

/* ---------- login com a conta Claude ---------- */
.steps.tight { margin: 10px 0 8px; }
.steps.tight li { margin-bottom: 3px; }

#loginCode {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font: 12.5px/1.4 ui-monospace, "Cascadia Code", Consolas, monospace;
}

.login-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

button.linkish {
  display: block;
  width: 100%;
  margin-top: 10px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- leitor de QR ---------- */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* moldura de mira: ajuda a enquadrar e a manter distância certa */
.scan-frame {
  position: absolute;
  width: min(72vw, 72vh);
  height: min(72vw, 72vh);
  border: 3px solid rgba(52, 211, 153, .9);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
  pointer-events: none;
}

.scan-status {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 96px);
  left: 16px;
  right: 16px;
  text-align: center;
  color: #fff;
  font-size: 14px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .8);
}

.scan-cancel {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 28px);
  left: 50%;
  transform: translateX(-50%);
  flex: none;
  min-width: 160px;
}

.token-state { font-size: 12px; color: var(--muted); text-align: right; }
.token-state.warn { color: #fbbf24; }
.token-state.bad { color: var(--danger); }
.error { font-size: 12.5px; color: var(--danger); margin: 10px 0 0; }

textarea {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  color: var(--text);
  padding: 11px 12px;
  font: 12px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace;
  resize: vertical;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--card-border);
}

.field.check { justify-content: flex-start; }
.field.check span { order: 2; }

select {
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  padding: 7px 9px;
  font-size: 13px;
}

input[type="checkbox"] { width: 19px; height: 19px; accent-color: var(--accent); }

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

button.primary, button.ghost, button.danger {
  flex: 1 1 auto;
  border: 0;
  border-radius: 11px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

button.primary { background: var(--accent); color: #062b20; }
button.ghost { background: var(--field); color: var(--text); }
button.danger { background: transparent; color: var(--danger); border: 1px solid rgba(248, 113, 113, .35); }
button:active { filter: brightness(.92); }

/* ---------- retrato estreito: medidores empilhados ---------- */
@media (max-width: 520px) and (orientation: portrait) {
  .gauges {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    height: clamp(300px, 62vh, 620px);
  }
  /* o Timer ocupa a linha toda, mas o desenho fica com a mesma escala dos outros */
  .gauge-slot.timer { grid-column: 1 / -1; grid-row: 2; }
  .gauge-slot.timer canvas { width: 66%; margin: 0 auto; }
  .card { max-width: 430px; }
}
