:root {
        color-scheme: dark;
        font-family: "Comic Sans MS", "Comic Sans", sans-serif;
        --chat-input-h: 58px;
        --header-h: 72px;
        --app-h: 100dvh;
        --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
        --sprite-h: clamp(350px, 54vh, 600px);
        --content-h: clamp(200px, 24vh, 280px);
        --sprite-anchor-left: 33%;
        --sprite-anchor-shift: 0px;
      }

      @media (max-width: 768px) {
        :root {
          --chat-input-h: 30px;
          --sprite-h: clamp(245px, 40vh, 340px);
          --content-h: clamp(155px, 22vh, 220px);
          --sprite-anchor-left: 50%;
          --sprite-anchor-shift: -50%;
        }

        body.page-front {
          overflow-y: hidden;
        }

        body.page-front main,
        body.page-front #app-main {
          overflow: hidden;
        }

        header {
          padding-inline: 12px;
        }

        .header-tabs {
          display: none;
        }

        .header-left,
        .header-right {
          display: none;
        }

        .header-title-wrapper {
          display: none;
        }

        .front-panel {
          min-height: auto;
        }

        .menu {
          display: none;
        }

        #front-page {
          height: calc(var(--app-h) - var(--header-layout-h, var(--header-h)));
        }

        .chat-section {
          padding-top: 4px;
        }

        .front-layout {
          grid-template-rows: minmax(210px, var(--sprite-h)) minmax(0, 1fr) auto;
          gap: 8px;
          align-content: stretch;
        }

        .front-content {
          height: auto;
        }

        .front-layout .chat-history {
          padding: 8px 10px 6px;
        }

        .front-controls,
        .front-interactions {
          gap: 0;
        }

        .chat-input-row {
          min-height: 30px;
          padding-inline: 4px;
          padding-bottom: calc(1px + var(--safe-area-inset-bottom));
        }

        .chat-input-row form,
        .chat-input-row #chat-form,
        .chat-form {
          gap: 6px;
        }

        .chat-form input {
          min-height: 30px;
          padding: 2px 8px;
          font-size: 16px;
        }

        .chat-form button,
        .chat-form button.voice {
          min-height: 30px;
          padding: 2px 8px;
          font-size: 0.8rem;
        }

        .vandfald-controls {
          gap: 6px;
        }

        .vandfald-button {
          padding: 4px 12px;
          font-size: 0.8rem;
        }

        .vandfald-progress {
          font-size: 0.95rem;
        }
      }

      #front-page {
        display: flex;
        flex-direction: column;
        gap: 12px;
        height: 100%;
        min-height: 0;
        overflow: hidden;
      }

      #front-page .section {
        background: transparent;
        padding: 0;
        box-shadow: none;
        margin-bottom: 0;
      }

      .chat-section {
        display: flex;
        flex-direction: column;
        gap: 8px;
        flex: 1 1 auto;
        min-height: 0;
        padding-top: 8px;
      }

      .front-layout {
        display: grid;
        grid-template-rows: var(--sprite-h) var(--content-h) auto;
        gap: 12px;
        height: 100%;
        min-height: 0;
        align-content: start;
      }

      .front-sprite,
      .front-content,
      .front-controls {
        min-height: 0;
      }

      .front-content {
        overflow: auto;
        display: flex;
        flex-direction: column;
        height: var(--content-h);
      }

      .front-controls {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        gap: 2px;
        min-height: 0;
      }

      .front-dynamic-area {
        display: flex;
        flex-direction: column;
        gap: 8px;
        min-height: 0;
        overflow: hidden;
      }


      .front-chat-history {
        flex: 2 1 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
      }

      .front-title {
        font-size: clamp(1.4rem, 3vw, 2.1rem);
        font-weight: bold;
        margin: 0;
        padding-left: 4px;
        color: #1a1a1a;
      }

      .front-tabs {
        position: static;
        top: auto;
        margin-top: 0;
        margin-bottom: 6px;
        align-self: stretch;
        z-index: auto;
        display: flex;
        gap: 8px;
        padding: 4px 8px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.18);
        border: 1px solid rgba(255, 255, 255, 0.6);
        backdrop-filter: blur(8px);
        justify-content: center;
        flex-direction: row;
        align-items: center;
        flex-wrap: nowrap;
      }

      .front-tab {
        flex: 0 0 auto;
        min-width: 0;
        border: 2px solid rgba(255, 255, 255, 0.7);
        border-radius: 999px;
        padding: 8px 12px;
        font-size: 0.9rem;
        font-weight: bold;
        background: rgba(255, 255, 255, 0.35);
        color: #1a1a1a;
        cursor: pointer;
        text-align: center;
      }

      .front-tab.is-active {
        background: rgba(255, 255, 255, 0.75);
      }

      @media (max-width: 768px) {
        .front-tabs {
          justify-content: flex-start;
          gap: 4px;
          padding: 0;
          border-radius: 0;
          background: transparent;
          border: none;
          box-shadow: none;
          backdrop-filter: none;
          max-width: 100%;
          overflow-x: auto;
          scrollbar-width: none;
        }

        .front-tabs::-webkit-scrollbar {
          display: none;
        }

        .front-tab {
          border: 1px solid rgba(26, 26, 26, 0.26);
          border-radius: 8px;
          padding: 3px 7px;
          font-size: 0.72rem;
          font-weight: 700;
          background: rgba(255, 255, 255, 0.92);
          box-shadow: none;
          text-shadow: none;
          -webkit-appearance: none;
          appearance: none;
        }

        .front-tab.is-active {
          background: #ffffff;
        }
      }

      .front-interactions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 2px;
        flex: 0 0 auto;
        margin-top: auto;
      }

      .chat-input-row {
        flex: 0 0 auto;
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 8px;
        padding-bottom: calc(2px + var(--safe-area-inset-bottom));
      }

      .chat-input-row form,
      .chat-input-row #chat-form {
        width: min(1100px, 100%);
        display: flex;
        gap: 8px;
      }

      .front-panel {
        display: none;
        width: 100%;
      }

      #front-page-layout .front-panel {
        display: none;
      }

      #front-page-layout[data-active-panel="subtitles"] .front-panel[data-panel="subtitles"],
      #front-page-layout[data-active-panel="vandfald"] .front-panel[data-panel="vandfald"] {
        display: flex;
      }

      .front-panel.is-active {
        display: block;
      }

      .front-chat-history.front-panel.is-active {
        display: flex;
      }

      .front-content .front-panel {
        flex: 1 1 auto;
        min-height: 0;
      }

      .front-panel.is-active.front-chat-history.is-hidden {
        display: none;
      }

      .front-panel.is-active[data-panel="vandfald"] {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 0;
      }

      .schwinkel-stage {
        flex: 0 0 auto;
        height: var(--sprite-h);
        min-height: 0;
        position: relative;
        border-radius: 36px;
        padding: 6px 10px;
        background: transparent;
        box-shadow: none;
        overflow: hidden;
        display: flex;
        align-items: flex-end;
        justify-content: center;
      }

      .front-dynamic-area.is-compact .schwinkel-stage {
        flex: 0 0 auto;
        height: var(--sprite-h);
      }

      #front-page:not(.active) .schwinkel-stage,
      #front-page:not(.active) .chat-section {
        display: none !important;
      }

      .schwinkel-stage-content {
        width: 100%;
        height: 100%;
        position: relative;
        overflow: hidden;
        display: flex;
        align-items: flex-end;
        justify-content: flex-start;
      }

      .schwinkel-stage-sprite {
        position: absolute;
        left: var(--sprite-anchor-left);
        bottom: 0;
        height: 100%;
        width: auto;
        max-width: none;
        max-height: none;
        object-fit: contain;
        transform-origin: bottom center;
        transform: translateX(var(--sprite-anchor-shift)) scale3d(3.2, 3.2, 1);
        cursor: pointer;
      }

      .chat-history {
        width: 100%;
        max-width: 100%;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        background: transparent;
        color: #1a1a1a;
        border-radius: 20px;
        padding: 16px;
        padding-bottom: calc(16px + var(--chat-input-h));
        display: flex;
        flex-direction: column;
        gap: 12px;
      }

      .chat-history .empty-state {
        color: rgba(120, 120, 120, 0.95);
        font-style: italic;
      }

      .chat-bubble {
        padding: 14px 18px;
        border-radius: 24px;
        width: auto;
        max-width: 100%;
        font-size: 0.85rem;
        line-height: 1.4;
        align-self: flex-start;
        display: inline-flex;
        flex-direction: column;
        word-break: break-word;
      }

      .chat-bubble-text {
        display: inline-block;
        max-width: 100%;
        width: auto;
      }

      .chat-bubble.user {
        background: #d0e7ff;
        color: #1a1a1a;
        align-self: flex-end;
      }

      .chat-bubble.assistant {
        background: #f7f7f7;
        color: #1a1a1a;
        border: 1px solid #e1e1e1;
        gap: 10px;
      }

      .chat-bubble.status {
        font-style: italic;
        border-style: dashed;
        opacity: 0.9;
      }

      .chat-bubble .replay-button {
        margin-top: 8px;
        border: none;
        border-radius: 999px;
        padding: 6px 12px;
        font-size: 0.85rem;
        background: rgba(255, 255, 255, 0.9);
        cursor: pointer;
        font-weight: bold;
        color: #1a1a1a;
        box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
        align-self: flex-start;
      }

      .chat-bubble .replay-button:hover {
        background: rgba(255, 255, 255, 1);
      }

      .chat-bubble-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 10px;
      }

      .chat-bubble-actions button {
        margin-top: 8px;
        border: none;
        border-radius: 999px;
        padding: 6px 12px;
        font-size: 0.85rem;
        background: rgba(255, 255, 255, 0.9);
        cursor: pointer;
        font-weight: bold;
        color: #1a1a1a;
        box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
        align-self: flex-start;
      }

      .chat-bubble-actions button:hover {
        background: rgba(255, 255, 255, 1);
      }

      .chat-form {
        display: flex;
        gap: 12px;
        align-items: center;
        width: 100%;
        height: 100%;
      }

      .chat-form input {
        flex: 1;
        border: 2px solid #d5d5d5;
        border-radius: 999px;
        padding: 5px 10px;
        font-size: 0.95rem;
        font-family: inherit;
        background: #ffffff;
        color: #1a1a1a;
      }

      .chat-form button {
        border: none;
        border-radius: 999px;
        padding: 5px 12px;
        font-size: 0.9rem;
        font-weight: bold;
        background: #ffffff;
        color: #1a1a1a;
        border: 2px solid #d5d5d5;
        cursor: pointer;
      }

      .chat-form button.voice {
        padding: 5px 10px;
        font-size: 0.9rem;
        background: #f8f8f8;
        border: 2px solid #d5d5d5;
      }

      .chat-form button:disabled {
        opacity: 0.6;
        cursor: not-allowed;
      }

      .chat-actions {
        display: flex;
        align-items: center;
        gap: 14px;
      }

      .vandfald-section {
        border-radius: 20px;
        padding: 14px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        height: 100%;
        min-height: 0;
      }

      .front-layout .front-chat-history {
        display: flex;
      }

      .front-layout .chat-history {
        display: flex;
        flex: 1 1 auto;
        padding-bottom: 16px;
      }

      .front-layout .chat-input-row {
        position: static;
        background: transparent;
        backdrop-filter: none;
      }

      .vandfald-controls {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
        align-items: center;
      }

      .vandfald-button {
        border: 2px solid #d5d5d5;
        border-radius: 999px;
        padding: 8px 18px;
        font-size: 0.9rem;
        font-weight: bold;
        background: #ffffff;
        color: #1a1a1a;
        cursor: pointer;
      }

      .vandfald-button:disabled {
        opacity: 0.4;
        cursor: not-allowed;
      }

      .vandfald-guide {
        min-height: 60px;
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.85);
        padding: 12px 16px;
        border: 1px solid #e3e3e3;
        display: flex;
        flex-direction: column;
        gap: 12px;
      }

      .vandfald-guide .vandfald-message {
        margin: 0;
        font-size: 1rem;
      }

      .vandfald-active-card-label {
        font-weight: bold;
      }

      .vandfald-active-card-label.red {
        color: #b91c1c;
      }

      .vandfald-progress {
        font-weight: bold;
        margin-left: auto;
      }

      .vandfald-audio-play {
        border: none;
        border-radius: 999px;
        padding: 6px 14px;
        background: #36c75a;
        color: #fff;
        font-weight: bold;
        cursor: pointer;
      }

      .vandfald-audio-add {
        border: none;
        border-radius: 999px;
        padding: 6px 14px;
        background: #ffb347;
        color: #1a1a1a;
        font-weight: bold;
        cursor: pointer;
        margin-right: 6px;
      }

      .vandfald-audio-record {
        border: none;
        border-radius: 999px;
        padding: 6px 14px;
        background: #1a74ff;
        color: #fff;
        font-weight: bold;
        cursor: pointer;
        margin-right: 6px;
      }

      .vandfald-audio-remove {
        border: none;
        border-radius: 999px;
        padding: 4px 12px;
        background: #ff3864;
        color: #fff;
        font-weight: bold;
        cursor: pointer;
        margin-left: 4px;
      }

      .vandfald-audio-cell {
        display: flex;
        flex-direction: column;
        gap: 6px;
      }

      .vandfald-audio-controls {
        display: flex;
        gap: 6px;
        align-items: center;
        justify-content: flex-end;
      }

      .vandfald-audio-name {
        font-size: 12px;
        color: #444;
      }

      .vandfald-audio-status {
        font-size: 12px;
        color: #444;
        font-weight: bold;
      }

      .vandfald-card-value {
        font-weight: bold;
      }

      .vandfald-card-value.red {
        color: #c8102e;
      }

      /* Keep these at file-end so mobile compaction wins the cascade. */
      @media (max-width: 768px) {
        body.page-front #app-main {
          min-height: 0;
          height: calc(var(--app-h) - var(--header-layout-h, var(--header-h)));
        }

        #front-page {
          height: calc(var(--app-h) - var(--header-layout-h, var(--header-h)));
          min-height: 0;
        }

        #front-page .chat-section {
          padding-top: 2px;
        }

        #front-page .front-layout {
          height: 100%;
          min-height: 0;
          grid-template-rows: minmax(200px, var(--sprite-h)) minmax(0, 1fr) auto;
          gap: 6px;
          align-content: stretch;
        }

        #front-page .front-layout .front-content {
          height: auto;
          min-height: 0;
        }

        #front-page .front-layout .front-chat-history {
          min-height: 0;
        }

        #front-page .front-layout .chat-history {
          min-height: 0;
          gap: 8px;
          padding: 8px 10px 2px;
        }

        #front-page .front-layout .front-controls,
        #front-page .front-layout .front-interactions {
          gap: 0;
        }

        #front-page .front-layout .chat-input-row {
          min-height: 24px;
          padding: 0 2px;
          padding-bottom: 0;
        }

        #front-page .front-layout .chat-input-row form,
        #front-page .front-layout .chat-input-row #chat-form,
        #front-page .front-layout .chat-form {
          gap: 4px;
        }

        #front-page .front-layout .chat-form input {
          min-height: 28px;
          padding: 1px 8px;
          font-size: 16px;
        }

        #front-page .front-layout .chat-form button,
        #front-page .front-layout .chat-form button.voice {
          min-height: 28px;
          padding: 1px 8px;
          font-size: 0.78rem;
        }

        #front-page .front-layout .vandfald-controls {
          gap: 6px;
        }

        #front-page .front-layout .vandfald-button {
          padding: 4px 12px;
          font-size: 0.8rem;
        }

        #front-page .front-layout .vandfald-progress {
          font-size: 0.95rem;
        }
      }
