:root {
  color-scheme: dark;
  --bg: #101315;
  --wallpaper:
    radial-gradient(circle at 16% 8%, rgba(154, 102, 67, 0.32), transparent 30rem),
    radial-gradient(circle at 88% 84%, rgba(44, 104, 116, 0.3), transparent 31rem),
    linear-gradient(148deg, #2c241f 0%, #1b1c22 48%, #071012 100%);
  --text: #fff9f1;
  --muted: rgba(255, 249, 241, 0.7);
  --faint: rgba(255, 249, 241, 0.48);
  --glass: rgba(255, 255, 255, 0.16);
  --glass-strong: rgba(255, 255, 255, 0.26);
  --glass-line: rgba(255, 255, 255, 0.26);
  --shadow: rgba(8, 9, 13, 0.42);
  --accent: #f8f3ea;
  --danger: #ffb0a8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

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

html {
  background: var(--wallpaper), var(--bg);
}

body {
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  background: transparent;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: -2px;
  z-index: 0;
  pointer-events: none;
  background:
    var(--wallpaper),
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 16%),
    rgba(0, 0, 0, 0.36);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

svg {
  display: block;
  width: 1.3rem;
  height: 1.3rem;
  fill: currentColor;
}

svg.line-icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

svg.symbol-icon {
  fill: currentColor;
  stroke: none;
}

[hidden] {
  display: none !important;
}

.screen {
  position: relative;
  z-index: 1;
  display: none;
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  padding: 0 18px calc(var(--safe-bottom) + 24px);
}

.screen.is-active {
  display: grid;
}

.entry-panel {
  width: min(420px, 100%);
  align-self: center;
  justify-self: center;
  display: grid;
  gap: 24px;
  padding: 34px 30px 30px;
  border: 1px solid var(--glass-line);
  border-radius: 40px;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 28px 80px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
}

.app-screen {
  --side-pad: 22px;
  --stack-gap: clamp(24px, 3.4svh, 38px);
  --header-cover-gap: clamp(14px, 2.1svh, 24px);
  --header-h: calc(var(--safe-top) + clamp(50px, 7.6svh, 64px));
  --player-h: clamp(196px, 26svh, 228px);
  --friends-h: 28px;
  --cover-size: min(
    calc(min(480px, 100vw) - var(--side-pad) - var(--side-pad)),
    calc(100svh - var(--safe-bottom) - var(--header-h) - var(--player-h) - var(--friends-h) - var(--header-cover-gap) - var(--stack-gap) - var(--stack-gap) - 18px)
  );
  position: fixed;
  inset: 0;
  width: min(480px, 100%);
  height: 100dvh;
  height: 100svh;
  margin: 0 auto;
  grid-template-rows: var(--header-h) auto;
  align-content: center;
  row-gap: var(--header-cover-gap);
  padding: 0 var(--side-pad) calc(var(--safe-bottom) + 10px);
  overflow: visible;
}

h1,
h2,
p {
  margin: 0;
}

.entry-panel h1 {
  font-family: "Chalkboard SE", "Comic Sans MS", "Comic Sans", cursive;
  font-size: clamp(2.7rem, 12vw, 4.25rem);
  line-height: 0.95;
  letter-spacing: 0;
  color: rgba(255, 249, 241, 0.96);
  text-align: center;
  text-shadow: 0 5px 30px rgba(0, 0, 0, 0.28);
}

.name-form {
  display: grid;
  gap: 14px;
}

.text-field {
  min-height: 58px;
  display: flex;
  align-items: center;
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  padding: 0 22px;
}

.text-field:focus-within {
  border-color: rgba(255, 255, 255, 0.52);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.16);
}

.text-field input,
#captionInput {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.text-field input::placeholder,
#captionInput::placeholder {
  color: rgba(255, 249, 241, 0.54);
}

.primary-button,
.secondary-button {
  min-height: 58px;
  border-radius: 999px;
  border: 0;
  padding: 0 18px;
  font-weight: 850;
}

.primary-button {
  background: var(--accent);
  color: #1f2128;
}

.secondary-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid var(--glass-line);
}

.primary-button:disabled,
button:disabled {
  cursor: default;
  opacity: 0.38;
}

.lock-header {
  position: relative;
  min-height: var(--header-h);
  display: grid;
  place-items: center;
  padding: var(--safe-top) 0 0;
}

.lock-header h1 {
  font-family: "Chalkboard SE", "Comic Sans MS", "Comic Sans", cursive;
  font-size: clamp(1.26rem, 4.9vw, 1.93rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  color: rgba(255, 249, 241, 0.96);
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.22);
}

.current-post-preview {
  position: absolute;
  left: 0;
  top: calc(var(--safe-top) + (var(--header-h) - var(--safe-top)) / 2);
  transform: translateY(-50%);
  width: 42px;
  min-width: 0;
  height: 42px;
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: rgba(255, 249, 241, 0.88);
  background: transparent;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.22);
}

.current-post-preview img {
  width: 42px;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.1);
}

.current-post-preview span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.debug-button {
  position: absolute;
  top: calc(var(--safe-top) + (var(--header-h) - var(--safe-top)) / 2);
  right: 0;
  transform: translateY(-50%);
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 999px;
  padding: 0 12px;
  color: rgba(255, 249, 241, 0.9);
  background: rgba(255, 255, 255, 0.13);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
}

.composer {
  display: grid;
  gap: var(--stack-gap);
  min-height: 0;
  overflow: visible;
  align-content: start;
  justify-items: stretch;
}

.cover {
  position: relative;
  width: var(--cover-size);
  height: var(--cover-size);
  justify-self: center;
  overflow: hidden;
  border-radius: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04)),
    rgba(255, 255, 255, 0.08);
  box-shadow: 0 22px 58px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  --preview-zoom: 1;
}

.cover video,
.cover img,
.cover canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover video {
  transform: scale(var(--preview-zoom));
  transform-origin: center;
  will-change: transform;
}

.cover video.is-mirrored {
  transform: scaleX(-1) scale(var(--preview-zoom));
}

.glass-player {
  display: grid;
  grid-template-rows: minmax(36px, auto) 1fr;
  gap: clamp(17px, 2svh, 24px);
  min-height: 0;
  height: var(--player-h);
  padding: clamp(21px, 2.65svh, 27px) 22px clamp(20px, 2.45svh, 25px);
  border: 1px solid var(--glass-line);
  border-radius: 38px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.08)),
    rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.34);
  backdrop-filter: blur(34px) saturate(170%);
  -webkit-backdrop-filter: blur(34px) saturate(170%);
}

.status-copy {
  display: grid;
  justify-items: center;
  gap: 1px;
  min-width: 0;
}

.display-name {
  max-width: 100%;
  color: rgba(255, 249, 241, 0.96);
  font-size: 0.88rem;
  line-height: 1.04;
  font-weight: 850;
  overflow-wrap: anywhere;
}

#captionInput {
  text-align: center;
  color: rgba(255, 249, 241, 0.76);
  font-size: 1.08rem;
  font-weight: 430;
  line-height: 1.2;
}

#captionInput::placeholder {
  color: rgba(255, 249, 241, 0.54);
  opacity: 1;
}

.creation-controls {
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  align-items: center;
  justify-items: center;
  gap: 14px;
  min-height: 86px;
}

.glass-icon-button,
.capture-action,
.send-action {
  display: inline-grid;
  place-items: center;
  border: 0;
  color: rgba(255, 255, 255, 0.92);
  background: transparent;
}

.glass-icon-button {
  width: 56px;
  height: 56px;
}

.glass-icon-button svg {
  width: 1.68rem;
  height: 1.68rem;
}

.glass-icon-button .photo-icon {
  width: 1.9rem;
  height: 1.9rem;
}

.glass-icon-button .flip-icon {
  width: 1.92rem;
  height: 1.92rem;
  stroke-width: 2.35;
}

.glass-icon-button .undo-icon {
  width: 1.8rem;
  height: 1.8rem;
}

.capture-action,
.send-action {
  width: 78px;
  height: 78px;
  border-radius: 999px;
}

.capture-action {
  border: 3px solid rgba(255, 255, 255, 0.98);
}

.capture-action span {
  width: 60px;
  height: 60px;
  border-radius: 999px;
  background: #fff;
  box-shadow: none;
}

.send-action {
  background: rgba(255, 255, 255, 0.94);
  color: #25242a;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.24);
}

.send-action svg {
  width: 2.05rem;
  height: 2.05rem;
  stroke-width: 2.45;
}

.friends-button {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border: 0;
  border-radius: 999px;
  padding: 0 13px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 249, 241, 0.88);
  font-size: 0.9rem;
  font-weight: 780;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

.status-line {
  min-height: 20px;
  color: rgba(255, 249, 241, 0.72);
  font-size: 0.88rem;
  text-align: center;
}

.status-line:empty {
  display: none;
}

.status-line.is-error {
  color: var(--danger);
}

.station-status {
  min-height: 0;
  margin-top: 0;
}

.debug-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 18px 14px calc(var(--safe-bottom) + 14px);
  background: rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
}

.debug-sheet {
  width: min(480px, 100%);
  max-height: min(680px, 86svh);
  overflow: hidden;
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--glass-line);
  border-radius: 30px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.08)),
    rgba(38, 37, 43, 0.78);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(34px) saturate(170%);
  -webkit-backdrop-filter: blur(34px) saturate(170%);
}

.debug-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.debug-sheet h2 {
  color: rgba(255, 249, 241, 0.94);
  font-size: 1.05rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.debug-close {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 0 13px;
  color: rgba(255, 249, 241, 0.86);
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.82rem;
  font-weight: 800;
}

.debug-list {
  min-height: 90px;
  max-height: calc(86svh - 92px);
  overflow: auto;
  display: grid;
  gap: 10px;
  padding-right: 2px;
}

.debug-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.09);
}

.debug-thumb {
  width: 76px;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.1);
}

.debug-meta {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.debug-name {
  color: rgba(255, 249, 241, 0.96);
  font-weight: 850;
  overflow-wrap: anywhere;
}

.debug-time {
  color: rgba(255, 249, 241, 0.66);
  font-size: 0.9rem;
  font-weight: 750;
}

.debug-delete {
  min-height: 34px;
  border: 1px solid rgba(255, 176, 168, 0.34);
  border-radius: 999px;
  padding: 0 12px;
  color: rgba(255, 218, 214, 0.96);
  background: rgba(255, 98, 84, 0.14);
  font-size: 0.78rem;
  font-weight: 850;
}

.debug-empty {
  align-self: center;
  color: rgba(255, 249, 241, 0.7);
  text-align: center;
  font-size: 0.94rem;
}

@media (max-width: 420px) {
  .screen {
    padding-left: 14px;
    padding-right: 14px;
  }

  .app-screen {
    --side-pad: 20px;
    --stack-gap: clamp(22px, 3.1svh, 34px);
    --header-cover-gap: clamp(13px, 1.8svh, 20px);
    --player-h: clamp(188px, 25svh, 214px);
  }

  .lock-header {
    padding: calc(var(--safe-top) + 6px) 0 8px;
  }

  .current-post-preview {
    width: 42px;
    height: 42px;
  }

  .current-post-preview img {
    width: 42px;
  }

  .debug-button {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .cover {
    border-radius: 36px;
  }

  .glass-player {
    padding: clamp(20px, 2.45svh, 24px) 18px clamp(18px, 2.2svh, 22px);
    border-radius: 34px;
  }

  .creation-controls {
    grid-template-columns: 56px 1fr 56px;
    gap: 10px;
    min-height: 88px;
  }

  .capture-action,
  .send-action {
    width: 74px;
    height: 74px;
  }

  .capture-action span {
    width: 56px;
    height: 56px;
  }
}
