:root {
  color-scheme: dark;
  font-family: "Segoe UI", Arial, sans-serif;
  color: #f0f1eb;
  background: #111210;
  --accent: #d7fa58;
  --muted: #a7aaa0;
  --line: #32352d;
  --mono: "Cascadia Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }

.topbar { position: absolute; inset: 0 0 auto; z-index: 1; }
.topbar-content {
  width: min(1120px, calc(100% - 36px));
  margin-inline: auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: inline-flex;
  align-items: center;
  color: inherit;
  font: 700 .88rem var(--mono);
  letter-spacing: .06em;
  text-decoration: none;
  text-transform: uppercase;
}
.brand-icon { position: relative; width: 23px; height: 24px; margin-right: 12px; }
.brand-icon i {
  position: absolute;
  inset: 3px auto auto 5px;
  width: 13px;
  height: 13px;
  border: 1px solid var(--accent);
  transform: rotate(45deg) scaleY(.65);
}
.brand-icon i:nth-child(2) { top: 7px; }
.brand-icon i:nth-child(3) { top: 11px; }
.connection { display: flex; align-items: center; gap: 9px; color: var(--muted); font: .875rem var(--mono); white-space: nowrap; }
.connection i { width: 7px; height: 7px; border-radius: 50%; background: #707366; }
.connection[data-online="true"] i { background: var(--accent); box-shadow: 0 0 11px #d7fa5860; }
.topbar-actions { display: flex; align-items: center; gap: 12px; min-width: 0; }
#language {
  display: inline-flex;
  flex: none;
  min-width: 2.4em;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #171915;
  color: inherit;
  font: .875rem var(--mono);
  text-decoration: none;
}
#language:hover { color: var(--accent); }

.layout {
  position: relative;
  min-height: 100svh;
  display: grid;
  grid-template-rows: minmax(min-content, 1fr) clamp(260px, 50svh, 480px) minmax(min-content, 1fr);
}
.introduction { align-self: end; padding: 70px 16px 2px; text-align: center; }
h1 {
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  line-height: 1;
  letter-spacing: -.065em;
  margin: 0;
  text-wrap: balance;
}
.title-period { color: var(--accent); }
.introduction p {
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.125rem);
  line-height: 1.5;
  margin: 12px 0 0;
  text-wrap: balance;
}
.remove {
  position: absolute;
  inset: 0;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
  touch-action: manipulation;
}
.remove:not(:disabled) .layer:not(.peeling) { pointer-events: auto; cursor: pointer; }
.remove:focus-visible { outline: none; }
.remove:focus-visible .strata .layer:last-child { outline: 2px solid #fff; outline-offset: 4px; }
.play {
  --layer-size: min(61vw, 40svh, 360px);
  position: relative;
  -webkit-user-select: none;
  user-select: none;
}
.info-trigger {
  position: absolute;
  top: 50%;
  left: min(calc(50% + var(--layer-size) * .707 + 16px), calc(100% - 56px));
  translate: 0 -50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #171915;
  color: var(--accent);
}
.info-trigger:hover, .play:has(#project-info:popover-open) .info-trigger { border-color: var(--accent); background: #252b16; }
.play-caption {
  position: absolute;
  inset: 6px 16px auto;
  text-align: center;
  pointer-events: none;
}
.action-label {
  display: inline-block;
  margin: 0;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #161812;
  color: #e4e6da;
  font: .875rem var(--mono);
  text-align: center;
}
.feedback { position: absolute; inset: 100% 0 auto; margin: 3px 0 0; color: var(--muted); font-size: .9rem; }

.visual {
  position: absolute;
  inset: 0;
}
#presence-background {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: radial-gradient(ellipse at center, #25291f 0%, #111210 77%);
}
.play-footer {
  position: absolute;
  z-index: 1;
  bottom: 0;
  left: 50%;
  translate: -50% 0;
  width: min(1120px, calc(100% - 28px));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.presence-count {
  min-width: 0;
  margin: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #171915;
  color: #e4e6da;
  font: .875rem var(--mono);
  overflow-wrap: anywhere;
  pointer-events: auto;
}
.presence-count:empty { display: none; }
.coffee-link {
  flex: none;
  display: grid;
  align-items: center;
  min-height: 36px;
  margin-left: auto;
  padding: 5px 11px;
  border: 1px solid #827139;
  border-radius: 4px;
  background: #232016;
  color: #ffe294;
  font: 600 .875rem var(--mono);
  text-decoration: none;
  pointer-events: auto;
}
.coffee-link:hover { border-color: #ffe294; background: #322c1d; }
.strata { position: absolute; inset: 0; }
.layer {
  --edge: hsl(var(--hue) 77% calc(75% - var(--depth) * 2.2%));
  position: absolute;
  top: calc(38.6% + var(--depth) * 1.9%);
  left: 50%;
  width: var(--layer-size);
  aspect-ratio: 1;
  border: 1px solid var(--edge);
  background: hsl(var(--hue) 59% 21% / .26);
  transform: translate(-50%, -50%) scaleY(.51) rotate(45deg);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.strata .layer:last-child, .layer.peeling {
  background: linear-gradient(130deg, hsl(var(--hue) 78% 53% / .47), hsl(var(--hue) 64% 22% / .64));
  box-shadow: inset 0 0 26px hsl(var(--hue) 88% 73% / .25), 0 0 28px hsl(var(--hue) 83% 64% / .24);
}
.remove:has(.layer:hover) .strata .layer:last-child, .remove:focus-visible .strata .layer:last-child { filter: brightness(1.22); }
.layer.peeling { pointer-events: none; }

.counters {
  align-self: end;
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 340px));
  justify-content: center;
  background: #171915f2;
  border-top: 1px solid var(--line);
}
.metric { min-width: 0; padding: clamp(13px, 2.2vh, 22px) clamp(16px, 3vw, 31px); }
.metric + .metric { border-left: 1px solid var(--line); }
.metric-label { display: block; color: var(--muted); font-size: .94rem; }
.metric strong, #elapsed { display: block; margin-top: 6px; color: var(--accent); font: 600 clamp(1.55rem, 3.6vw, 2.75rem) var(--mono); letter-spacing: -.05em; }
.metric sup { font-size: .55em; }
#remaining, #elapsed { font-size: clamp(.9rem, 3.4vw, 2rem); white-space: nowrap; }
.timer-status { margin: 3px 0 0; color: var(--muted); font-size: .875rem; }
.idle-timer { margin: 5px 0 0; color: var(--muted); font-size: .875rem; }
#idle-left { margin-left: .35em; color: #f0f1eb; font: 600 .875rem var(--mono); }
.exact-trigger {
  margin-top: 8px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .875rem;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: .2em;
}
.exact-trigger:hover { color: #fff; }
.popover {
  position: fixed;
  padding: 0;
  border: 1px solid #4d5540;
  border-radius: 12px;
  background: #1b1e17;
  color: #f0f1eb;
  box-shadow: 0 12px 42px #000b;
}
#project-info {
  inset: 0;
  width: min(450px, calc(100% - 32px));
  max-height: calc(100svh - 32px);
  height: fit-content;
  margin: auto;
  overflow: auto;
  user-select: text;
}
.info-body { padding: 16px; color: #e8ebdf; line-height: 1.6; }
.info-body p { margin: 0; }
.info-body p + p { margin-top: 12px; }
#exact-panel {
  inset: auto 0 clamp(114px, 17svh, 150px);
  width: min(650px, calc(100% - 24px));
  max-height: min(420px, 52svh);
  margin: 0 auto;
  overflow: hidden;
}
#exact-panel:popover-open { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.popover-header h2 { margin: 0; font-size: 1rem; }
.popover-close {
  flex: 0 0 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: inherit;
  font: 1.4rem/1 var(--mono);
}
.popover-close:hover { background: #30362a; }
.exact-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 14px 16px; }
.exact-scroll:focus-visible { outline-offset: -3px; }
#exact { color: #e8ebdf; font: .88rem/1.65 var(--mono); overflow-wrap: anywhere; margin: 0; }

@media (max-width: 700px), (max-height: 530px) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100svh;
    height: 100dvh;
    min-width: 0;
  }
  .topbar {
    position: relative;
    inset: auto;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }
  .topbar-content { width: calc(100% - 24px); min-height: 44px; gap: 8px; }
  .topbar-actions { gap: 8px; }
  .brand { white-space: nowrap; }
  .connection { white-space: normal; overflow-wrap: anywhere; }
  .connection i { flex: 0 0 7px; }
  main { min-height: 0; min-width: 0; }
  .layout { height: 100%; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; }
  .introduction {
    padding: 4px max(14px, env(safe-area-inset-right)) 2px max(14px, env(safe-area-inset-left));
  }
  h1 { font-size: clamp(1.65rem, min(7vw, 8dvh), 2.5rem); }
  .introduction p { margin-top: 5px; font-size: .875rem; line-height: 1.3; }
  .play { container-type: size; --layer-size: min(57vw, 61cqh, 310px); }
  .layer { top: calc(41% + var(--depth) * 1.52%); }
  .play-caption { top: 3px; }
  .action-label { padding: 3px 8px; font-size: .8125rem; }
  .feedback { font-size: .8125rem; }
  .play-footer {
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: 5px;
    translate: none;
    width: auto;
  }
  .presence-count, .coffee-link { font-size: .75rem; }
  .coffee-link { min-height: 34px; padding-inline: 8px; }
  .info-trigger {
    left: auto;
    right: max(12px, env(safe-area-inset-right));
    top: 31%;
    width: 40px;
    height: 40px;
  }
  .counters {
    align-self: stretch;
    margin-top: 0;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    grid-template-columns: minmax(0, .75fr) minmax(0, 1.25fr);
  }
  .metric { padding: 7px 12px; }
  .metric-label, .timer-status, .idle-timer, .exact-trigger { font-size: .8125rem; }
  .metric strong { margin-top: 3px; font-size: 1.25rem; }
  #remaining { font-size: clamp(.875rem, 3.7vw, 1.25rem); }
  #elapsed { margin-top: 0; font-size: clamp(1rem, 4vw, 1.4rem); }
  .exact-trigger { margin-top: 2px; padding-block: 4px; }
  #exact-panel {
    inset: 0;
    height: fit-content;
    max-height: calc(100dvh - 32px);
    margin: auto;
  }
  .metric.timer-metric {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 3px 12px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .idle-timer { flex-basis: 100%; margin-top: 0; }
}

@media (orientation: landscape) and (max-height: 530px) and (min-width: 540px) {
  .topbar-content { min-height: 38px; }
  .counters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric.timer-metric {
    grid-column: auto;
    display: grid;
    border-left: 1px solid var(--line);
    border-top: 0;
  }
  .info-trigger {
    top: 50%;
    right: auto;
    left: calc(50% + var(--layer-size) * .707 + 16px);
  }
}

@media (max-width: 370px) {
  .brand { letter-spacing: 0; font-size: .75rem; }
  .brand-icon { margin-right: 6px; }
  .connection { font-size: .75rem; }
  .topbar-content, .topbar-actions { gap: 6px; }
  .connection { white-space: normal; overflow-wrap: anywhere; }
  .metric strong { font-size: 1.25rem; }
}
