@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;700;800&display=swap");

@font-face {
  font-family: "MonoSpec";
  src: url("MonoSpec-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
}

html,
body {
  margin: 0;
  padding: 0;
  background: #ffffff;
  overflow: hidden;
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  height: 100%;
  transform: translateZ(0);
  backface-visibility: hidden;
}

#app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(220px, 340px) minmax(440px, 1fr) minmax(
      240px,
      320px
    );
  gap: clamp(20px, 4vw, 56px);
  align-items: start;
  padding: clamp(26px, 4vw, 54px);
  z-index: 20;
  pointer-events: none;
}

canvas {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: transparent;
}

#char-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  opacity: 1;
  overflow: hidden;
}

.char-part {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: center center;
  visibility: hidden;
}

video {
  display: none;
}

#left-panel,
#right-panel {
  pointer-events: auto;
}

#left-panel {
  grid-column: 1;
  max-width: 340px;
  color: #111;
}

#left-panel h1 {
  margin: 0;
  font-family: "MonoSpec", monospace;
  /* font-size: clamp(28px, 3vw, 42px); */
  line-height: 1.05;
  letter-spacing: 0.07em;
  font-weight: 800;
}

#left-panel p {
  margin: 24px 0 0;
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 31px;
  /* font-size: clamp(16px, 1.2vw, 24px); */
  font-size: 0.8rem;
  line-height: 1.35;
  /* max-width: 280px; */
}

#right-panel {
  grid-column: 3;
  justify-self: end;
  width: 230px;
  color: #111;
}

#right-panel h2 {
  margin: 0;
  font-family: "MonoSpec", monospace;
  font-size: clamp(16px, 1.2vw, 26px);
  letter-spacing: 0.08em;
  font-weight: 800;
}

#character-copy {
  margin: 14px 0 0;
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: clamp(15px, 1vw, 22px);
  line-height: 1.3;
}

#character-copy strong {
  font-weight: 700;
}

.section-gap {
  margin-top: 38px !important;
}

#char-bar {
  margin-top: 14px;
  width: 190px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.char-btn {
  width: 52px;
  height: 52px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  transition:
    border-color 0.2s,
    transform 0.15s;
  padding: 0;
  position: relative;
  pointer-events: auto !important;
  -webkit-user-select: none;
  user-select: none;
}

.char-btn img {
  opacity: 1;
  width: 78%;
  height: 78%;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  pointer-events: none;
}

.char-btn:hover {
  transform: translateY(-1px);
}

.char-btn.active {
  border-color: #222;
}

#camera-toggle-btn {
  margin-top: 14px;
  width: 184px;
  height: 56px;
  border: 2px solid #333;
  border-radius: 999px;
  background: transparent;
  color: #333;
  font-family: "MonoSpec", monospace;
  font-size: clamp(18px, 1vw, 22px);
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition:
    background 0.2s,
    color 0.2s;
  pointer-events: auto !important;
  -webkit-user-select: none;
  user-select: none;
}

#camera-toggle-btn img {
  width: 28px;
  height: auto;
  display: block;
  pointer-events: none;
}

#rec-btn {
  margin-top: 1rem;
  width: 184px;
  height: 56px;
  border: none;
  border-radius: 999px;
  background: #cc2a2a;
  color: #fff;
  font-family: "MonoSpec", monospace;
  font-size: clamp(18px, 1vw, 22px);
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: opacity 0.2s;
  pointer-events: auto !important;
  -webkit-user-select: none;
  user-select: none;
}

#rec-btn.recording {
  background: #cc2a2a;
  color: #fff;
  animation: rec-pulse 1.4s ease-in-out infinite;
}

#rec-btn.save {
  background: #0f5ff4;
  color: #fff;
}

@keyframes rec-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.65;
  }
}

@keyframes fun-part-flow {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.fun-part-gradient {
  color: #000200;
}

.fun-part-gradient.animating {
  background: linear-gradient(
    90deg,
    #fe1001,
    #f82ba6,
    #115ff4,
    #f82ba6,
    #fe1001
  );
  background-size: 300% 300%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: fun-part-flow 4s ease infinite;
}

#kca-logo {
  position: fixed;
  left: clamp(28px, 4vw, 54px);
  bottom: clamp(26px, 3vw, 44px);
  z-index: 21;
  width: clamp(62px, 6vw, 92px);
  height: auto;
  pointer-events: none;
}

#rec-timer {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: rgba(200, 0, 0, 0.82);
  color: #fff;
  font-family: monospace;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 0.12em;
  padding: 6px 20px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

:root {
  --desktop-frame-width: clamp(300px, 28vw, 380px);
  --desktop-frame-inset: 12px;
}

#desktop-center-frame {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: var(--desktop-frame-width);
  aspect-ratio: 607 / 1080;
  border-radius: 20px;
  border: 3px solid #222;
  overflow: hidden;
  /* box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.18),
    0 16px 34px rgba(0, 0, 0, 0.24); */
  pointer-events: none;
  z-index: 12;
  opacity: 1;
}

#mobile-live-pill {
  position: fixed;
  top: calc(
    50% - ((var(--desktop-frame-width) * 1080 / 607) / 2) +
      var(--desktop-frame-inset)
  );
  left: calc(
    50% + (var(--desktop-frame-width) / 2) - 100px - var(--desktop-frame-inset)
  );
  right: auto;
  width: 100px;
  height: 160px;
  border-radius: 16px;
  background: #a6a3a5;
  overflow: hidden;
  z-index: 26;
  pointer-events: none;
  display: block;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
}

body.show-live-preview #mobile-live-pill {
  opacity: 1;
  visibility: visible;
}

#mobile-live-pill .mobile-preview-video {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#mobile-controls {
  display: none;
}

.mobile-preview-video {
  display: none;
}

#sheet-handle {
  display: none;
}

@media (max-width: 992px) {
  :root {
    --sheet-title-size: clamp(20px, 5.2vw, 24px);
    --sheet-copy-size: clamp(14px, 4vw, 15px);
    --sheet-heading-size: clamp(16px, 6.8vw, 24px);
  }

  #desktop-center-frame {
    display: block;
    inset: 0;
    left: auto;
    top: auto;
    transform: none;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  #char-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block !important;
    overflow: visible;
  }

  #app-shell {
    inset: auto 0 0 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: #ffffff !important;
    border-top: 2px solid #222;
    border-radius: 42px 42px 0 0;
    padding: 34px;
    max-height: 84dvh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    pointer-events: auto;
    z-index: 300;
    transform: translateY(105%);
    transition: transform 0.35s ease;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  #app-shell::-webkit-scrollbar {
    display: none;
  }

  body.mobile-sheet-open #app-shell {
    transform: translateY(0);
  }

  #app-shell::before {
    content: none;
  }

  #sheet-handle {
    display: block;
    width: 140px;
    height: 28px;
    border: none;
    border-radius: 999px;
    background: transparent;
    align-self: center;
    margin: 0 0 18px;
    padding: 0;
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  #sheet-handle::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 120px;
    height: 7px;
    border-radius: 999px;
    background: #c6c6c8;
    transform: translate(-50%, -50%);
    pointer-events: none;
  }

  #left-panel,
  #right-panel {
    width: 100%;
    max-width: none;
    justify-self: auto;
    pointer-events: auto;
  }

  #char-bar {
    pointer-events: auto;
  }

  #right-panel {
    order: 1;
  }

  #left-panel {
    order: 2;
    margin-top: 44px;
  }

  #char-bar {
    width: 100%;
    grid-template-columns: repeat(6, 52px);
    justify-content: flex-start;
    gap: 12px;
    margin-top: 16px;
    overflow-x: auto;
    padding-bottom: 2px;
    pointer-events: auto !important;
  }

  #right-panel h2 {
    font-size: var(--sheet-title-size);
    line-height: 1.1;
    letter-spacing: 0.06em;
  }

  #character-copy {
    font-size: var(--sheet-copy-size);
    line-height: 1.35;
    margin-top: 2rem;
  }

  .section-gap {
    margin-top: 38px !important;
  }

  .char-btn {
    width: 52px;
    height: 52px;
    /* border-width: 2px; */
  }

  .char-btn.active {
    border-color: #111;
    border-width: 2px;
  }

  #camera-toggle-btn {
    width: 100%;
    max-width: 184px;
    margin-top: 20px;
  }

  #left-panel h1 {
    font-size: var(--sheet-heading-size);
    line-height: 1.08;
    letter-spacing: 0.065em;
    white-space: nowrap;
  }

  #left-panel h1 br {
    display: none;
  }

  #left-panel p {
    margin-top: 14px;
    max-width: none;
    font-size: var(--sheet-copy-size);
    line-height: 1.38;
  }

  #kca-logo {
    order: 3;
    position: static;
    align-self: center;
    width: clamp(48px, 10vw, 72px);
    margin: 38px auto 6px;
  }

  #rec-btn,
  #camera-toggle-btn {
    display: none;
  }

  #mobile-live-pill {
    top: 32px;
    right: 32px;
    left: auto;
    display: block;
  }

  #mobile-live-pill .mobile-preview-video {
    display: block;
  }

  #mobile-controls {
    display: grid;
    grid-template-columns: 62px min(62vw, 224px) 62px;
    align-items: center;
    justify-content: center;
    column-gap: 18px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
    z-index: 250;
    pointer-events: none;
  }

  #right-panel .char-btn,
  #right-panel #camera-toggle-btn,
  #right-panel #rec-btn,
  #sheet-handle,
  #camera-toggle-btn-mobile,
  #mobile-menu-btn,
  #rec-btn-mobile,
  button {
    touch-action: manipulation;
    pointer-events: auto !important;
    position: relative;
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
  }

  .char-btn:active,
  .char-btn:focus-visible {
    transform: translateY(-2px);
    border-color: #111;
    /* background: #d0d0d0; */
  }

  #bg-btn:active,
  #bg-btn:focus-visible {
    background: #f0f0f0;
  }

  #rec-btn-mobile:active,
  #rec-btn-mobile:focus-visible {
    opacity: 0.85;
    transform: scale(0.98);
  }

  #mobile-menu-btn:active,
  #mobile-menu-btn:focus-visible {
    opacity: 0.85;
    transform: scale(0.95);
  }

  #camera-toggle-btn-mobile,
  #rec-btn-mobile,
  #mobile-menu-btn {
    pointer-events: auto;
  }

  #camera-toggle-btn-mobile {
    grid-column: 1;
    width: 62px;
    height: 62px;
    border: 1px solid #333;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
  }

  #camera-toggle-btn-mobile img {
    width: 26px;
    height: auto;
    display: block;
    pointer-events: none;
  }

  #camera-toggle-btn-mobile:active,
  #camera-toggle-btn-mobile:focus-visible {
    opacity: 0.85;
    /* transform: scale(1); */
  }

  #rec-btn-mobile {
    grid-column: 2;
    width: min(62vw, 224px);
    height: 64px;
    border: none;
    border-radius: 999px;
    background: #cc2a2a;
    color: #fff;
    font-family: "MonoSpec", monospace;
    font-size: clamp(20px, 4.2vw, 30px);
    letter-spacing: 0.05em;
    font-weight: 700;
    cursor: pointer;
  }

  #rec-btn-mobile.recording {
    background: #cc2a2a;
    color: #fff;
    animation: rec-pulse 1.4s ease-in-out infinite;
  }

  #rec-btn-mobile.save {
    background: #0f5ff4;
    color: #fff;
  }

  #mobile-menu-btn {
    grid-column: 3;
    width: 62px;
    height: 62px;
    border: 1px solid #333;
    border-radius: 50%;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    align-items: center;
    cursor: pointer;
  }

  #mobile-menu-btn span {
    width: 24px;
    height: 3px;
    border-radius: 999px;
    background: #101012;
  }

  body.mobile-sheet-open #mobile-menu-btn {
    background: #fff;
  }

  #rec-timer {
    top: 12px;
  }
}

#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  opacity: 1;
  visibility: visible;
  transition:
    opacity 0.5s ease,
    visibility 0.5s;
}

#loading-overlay span {
  font-family: "MonoSpec", monospace;
  font-size: clamp(13px, 1.4vw, 18px);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #111;
}

#loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

#saving-toast {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 400;
  background: rgba(15, 15, 15, 0.88);
  color: #fff;
  font-family: "Inter", sans-serif;
  font-size: clamp(13px, 1.1vw, 15px);
  padding: 14px 28px;
  border-radius: 16px;
  backdrop-filter: blur(12px);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.2s ease,
    visibility 0.2s;
  text-align: center;
  max-width: 260px;
  line-height: 1.5;
}

#saving-toast.visible {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 576px) {
  /* Fix bottom controls bar overflowing narrow viewports.
     Switch the center column to 1fr so the record button fills
     remaining space instead of using a fixed min(62vw, 224px) width
     that can exceed the viewport when side buttons + gaps are added. */
  #mobile-controls {
    grid-template-columns: 52px 1fr 52px;
    column-gap: 10px;
    padding: 0 16px;
    box-sizing: border-box;
  }

  #camera-toggle-btn-mobile,
  #mobile-menu-btn {
    width: 52px;
    height: 52px;
  }

  #rec-btn-mobile {
    width: 100%;
    height: 56px;
    font-size: clamp(16px, 4.5vw, 22px);
  }

  /* Keep all 6 characters in one row and shrink them to fit.
     1fr columns divide available width equally; buttons fill
     their cell via width/height: 100% with aspect-ratio: 1. */
  #char-bar {
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    overflow-x: visible;
    width: 100%;
  }

  #char-bar .char-btn {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }

  /* Prevent the heading from being clipped by overflow-x: hidden.
     Allow it to wrap and scale the font down further so it doesn't
     push outside the sheet padding at narrow widths. */
  #left-panel h1 {
    white-space: normal;
    font-size: clamp(13px, 4.6vw, 20px);
  }
}

/* ── Unsupported browser fallback (Firefox) ─────────────────────── */
body.unsupported-page {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  overflow: auto;
}

.unsupported-box {
  text-align: center;
  max-width: 400px;
  padding: 20px;
  font-family: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 16px;
  color: #333;
  line-height: 1.5;
}

.unsupported-box p {
  margin: 0 0 8px;
}

.unsupported-box b {
  font-weight: 600;
}
