@font-face {
  font-family: "Familjen Grotesk";
  src: url("../vendor/fonts/familjen-grotesk.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --abyss: #04303b;
  --deep: #07404d;
  --water: #0d5563;
  --shoal: #2b8290;
  --mist: #a9d3d2;
  --foam: #eefaf6;
  --flag: #d92b22;
  --flag-bright: #ff6a58;
  --gap: clamp(12px, 2vw, 20px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--abyss);
  color: var(--foam);
  font: 400 16px/1.5 "Familjen Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }

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

button {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
}

:focus-visible { outline: 2px solid var(--foam); outline-offset: 2px; }

.primary { background: var(--flag); color: #fff; font-weight: 700; }
.primary:hover { background: #c4241c; }
.primary:disabled { background: var(--water); color: var(--mist); cursor: default; }
.quiet { background: transparent; color: var(--foam); box-shadow: inset 0 0 0 1px var(--shoal); }
.quiet:hover { background: var(--water); }

.bar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 8px var(--gap);
  padding-top: max(8px, env(safe-area-inset-top));
  flex: none;
}

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
#offline { margin-left: auto; color: var(--mist); font-size: 14px; }
body[data-state="empty"] #add { display: none; }

#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 22px;
  padding: var(--gap) clamp(20px, 7vw, 96px) clamp(40px, 11vh, 110px);
  background: linear-gradient(180deg, var(--abyss) 0%, #06475a 58%, #0f7486 100%);
}

#welcome h1 {
  max-width: 9em;
  font-size: clamp(60px, 13vw, 176px);
  line-height: .9;
  letter-spacing: -.035em;
  font-weight: 700;
  color: var(--flag-bright);
  animation: resurface 2.2s cubic-bezier(.3, 0, .2, 1) both;
}

@keyframes resurface {
  from { color: #2d8c9b; }
  to { color: var(--flag-bright); }
}

#welcome p { max-width: 34em; font-size: clamp(17px, 1.7vw, 21px); }
#welcome .fine { max-width: 40em; color: var(--mist); font-size: 15px; }
#welcome .primary { min-height: 54px; padding: 0 28px; font-size: 18px; }

body.dragging #welcome, body.dragging #stage { box-shadow: inset 0 0 0 3px var(--flag-bright); }

#editor {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template:
    "files panel" auto
    "stage panel" minmax(0, 1fr)
    "transport panel" auto / minmax(0, 1fr) 320px;
}

#files {
  grid-area: files;
  display: flex;
  gap: 4px;
  padding: 0 var(--gap) 8px;
  overflow-x: auto;
}

#files button {
  flex: none;
  max-width: 220px;
  min-height: 36px;
  padding: 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: transparent;
  color: var(--mist);
  font-size: 14px;
}

#files button[aria-current="true"] { background: var(--water); color: var(--foam); }

#stage {
  grid-area: stage;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  background: #02252e;
  overflow: hidden;
}

#frame { position: relative; touch-action: none; user-select: none; }
#view { display: block; width: 100%; height: 100%; }

#handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 44px;
  margin-left: -22px;
  cursor: ew-resize;
}

#handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 21px;
  width: 2px;
  background: #fff;
}

/* The diver-down flag: red field, white diagonal */
.grip {
  position: absolute;
  top: 50%;
  left: 4px;
  width: 36px;
  height: 28px;
  margin-top: -14px;
  border-radius: 2px;
  background: linear-gradient(to bottom right, var(--flag) 0 40%, #fff 40% 60%, var(--flag) 60%);
  box-shadow: 0 1px 6px rgb(0 20 26 / .55);
}

.side {
  position: absolute;
  top: 10px;
  padding: 2px 8px;
  background: rgb(2 37 46 / .72);
  border-radius: 2px;
  font-size: 13px;
  pointer-events: none;
}

.side.left { left: 10px; }
.side.right { right: 10px; }

#busy {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(320px, 80%);
  padding: 10px 14px;
  background: rgb(2 37 46 / .9);
  border-radius: 3px;
  font-size: 14px;
}

#problem {
  position: absolute;
  inset: auto var(--gap) var(--gap);
  padding: 12px 14px;
  background: #5c1612;
  border-left: 4px solid var(--flag-bright);
  font-size: 15px;
}

.meter { display: block; height: 4px; background: var(--water); overflow: hidden; }
.meter span { display: block; width: 0; height: 100%; background: var(--flag-bright); }

#transport {
  grid-area: transport;
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 8px var(--gap);
}

body[data-kind="still"] #transport { display: none; }
#play { flex: none; width: 76px; padding: 0; }
#time { flex: none; min-width: 92px; text-align: right; color: var(--mist); font-size: 14px; font-variant-numeric: tabular-nums; }

input[type="range"] { flex: 1; width: 100%; height: 44px; margin: 0; background: transparent; accent-color: var(--flag-bright); }

#panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px var(--gap) var(--gap);
  padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--deep);
}

#panel h2 { padding-top: 8px; font-size: 20px; line-height: 1.2; font-weight: 700; }

#looks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 8px; }

.look {
  display: block;
  padding: 0;
  min-height: 0;
  background: transparent;
  text-align: left;
  font-size: 14px;
  line-height: 1.3;
  color: var(--mist);
}

.look canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--water);
  margin-bottom: 4px;
  outline: 3px solid transparent;
  outline-offset: -3px;
}

.look[aria-checked="true"] { color: var(--foam); font-weight: 700; }
.look[aria-checked="true"] canvas { outline-color: var(--flag-bright); }
#hint { min-height: 3em; color: var(--mist); font-size: 14px; }
.range > span { display: flex; justify-content: space-between; font-weight: 700; }
.range output { font-weight: 400; color: var(--mist); font-variant-numeric: tabular-nums; }

#rawMode { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; border: 0; font-size: 15px; }
#rawMode legend { padding: 0; margin-bottom: 4px; font-weight: 700; }
#rawMode label { display: flex; align-items: center; gap: 8px; min-height: 32px; }
#rawMode input { accent-color: var(--flag-bright); }

#keeps { color: var(--mist); font-size: 14px; }
#actions { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
#actions .primary { width: 100%; min-height: 50px; font-size: 17px; }
#progress { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
#result { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }

@media (max-width: 820px) {
  body { height: auto; min-height: 100%; }
  #editor {
    display: flex;
    flex-direction: column;
  }
  #stage { flex: none; height: 52vh; }
  #panel { overflow: visible; padding-bottom: 96px; }
  #looks { display: flex; gap: 8px; overflow-x: auto; margin-inline: calc(var(--gap) * -1); padding: 0 var(--gap) 10px; scroll-padding-inline: var(--gap); scroll-snap-type: x proximity; }
  .look { flex: 0 0 112px; scroll-snap-align: start; }
  #hint { min-height: 0; }
  #actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    padding: 10px var(--gap);
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: var(--deep);
    box-shadow: 0 -1px 0 var(--water);
  }
}

@media (prefers-reduced-motion: reduce) {
  #welcome h1 { animation: none; }
}
