/*
 * BREVITY — APP STYLES
 * Single stylesheet for the app
 */

/* Base fonts */
@font-face {
    font-family: 'Andale Mono';
    src: local('Andale Mono'), url('/fonts/AndaleMono.woff2') format('woff2'),
         url('/fonts/AndaleMono.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Sans';
    src: url('/fonts/IBMPlexSans-Light.woff2') format('woff2');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Sans';
    src: url('/fonts/IBMPlexSans-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('/fonts/IBMPlexMono-Light.woff2') format('woff2');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('/fonts/IBMPlexMono-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* Global variables and reset */
:root {
    --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --text-primary: #f2f2f2;
    --text-body: #bebebe;
    --text-secondary: #888888;
    --text-muted: #767676;
    --text-inactive: #555555;
    --bg-color: #000000;
    --transition-base: 0.3s ease;
    --container-padding: 2rem;
}

@media (max-width: 768px) {
    :root {
        --container-padding: 1.5rem;
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    width: 100%;
    height: 100%;
    min-height: 100%;
}

body {
    font-family: var(--font-body);
    line-height: 1.6;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

img, video, canvas, svg, iframe {
    max-width: 100%;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
}

a {
    color: var(--text-primary);
    text-decoration: none;
    position: relative;
    display: inline-block;
    transition: color var(--transition-base);
    z-index: 1;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

a::after {
    content: '';
    position: absolute;
    bottom: 1px;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: #fff;
    transition: height 0.2s, bottom 0.2s;
    z-index: -1;
}

@media (hover: hover) {
    a:hover {
        color: #000;
    }

    a:hover::after {
        height: 100%;
        bottom: 0;
    }
}

::selection {
    background: #fff;
    color: #000;
}

/* Shared layout and footer */
.content-wrapper {
    position: relative;
    width: 100%;
    opacity: 0;
    transition: opacity 0.3s ease-out;
    padding-bottom: env(safe-area-inset-bottom);
}

.content-wrapper.visible {
    opacity: 1;
}

footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.logo {
    display: inline-block;
    margin-bottom: 0.35rem;
    width: 20px;
    height: 22px;
    position: relative;
    cursor: pointer;
}

.logo::after {
    display: none !important;
}

.logo .mb-path {
    fill: #fff;
}

.logo svg {
    width: 100%;
    height: 100%;
    display: block;
}

.footer-text {
    font-size: 0.65rem;
    line-height: 1.35;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 0.25rem;
}

/* Shared code/result block styles */
code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85em;
    background-color: #1a1a1a;
    padding: 0.15em 0.4em;
    border-radius: 3px;
    color: #e0e0e0;
}

.code-block-wrapper {
    position: relative;
    margin: 1.5rem 0;
}

pre {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    background-color: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 1.5rem;
    margin: 0;
    overflow-x: auto;
    color: #e0e0e0;
}

pre code {
    padding: 0;
    background: none;
}

.copy-button {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 0.5rem;
    opacity: 1;
    color: #e3e3e3;
    transition: opacity 0.2s, background-color 0.2s;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-button:hover {
    background-color: #3a3a3a;
}

.copy-button:active {
    background-color: #4a4a4a;
    transform: scale(0.95);
}

.copy-button svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: currentColor;
    transition: fill 0.2s;
}

.copy-button::before {
    content: 'Copy Code';
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 0.5rem;
    padding: 0.35rem 0.65rem;
    background-color: #1a1a1a;
    border: 1px solid #444;
    border-radius: 4px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.75rem;
    color: var(--text-primary);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 20;
}

.copy-button::after {
    content: '';
    position: absolute;
    bottom: 100%;
    right: 0.75rem;
    margin-bottom: 0.25rem;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #444;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 21;
}

@media (hover: hover) {
    .copy-button:hover::before,
    .copy-button:hover::after {
        opacity: 1;
        visibility: visible;
    }
}

.copy-button:focus-visible::before,
.copy-button:focus-visible::after {
    opacity: 1;
    visibility: visible;
}

.copy-button.copied {
    background-color: #3a3a3a;
    border-color: #555;
}

.copy-button.copied svg {
    fill: var(--text-primary);
}

.copy-button.copied::before {
    content: 'Copied!';
    background-color: #1a1a1a;
    border-color: #555;
    color: var(--text-primary);
    opacity: 1;
    visibility: visible;
}

.copy-button.copied::after {
    border-top-color: #555;
    opacity: 1;
    visibility: visible;
}

.copy-button.fading-out::before,
.copy-button.fading-out::after {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

/* Suppress default focus ring on mouse/touch; keep only keyboard-triggered focus */
:focus:not(:focus-visible) {
    outline: none !important;
    box-shadow: none !important;
}

/* Global focus style */
:focus-visible {
    outline: none !important;
    box-shadow: 0 0 0 2px black, 0 0 0 4px var(--text-primary) !important;
    border-radius: 2px !important;
}

/* Page layout — exact viewport height flex column */
.app-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

@supports (height: 100svh) {
    .app-page {
        height: 100svh;
    }
}

/* App header */
.app-header {
    max-width: 38rem;
    margin: 0 auto;
    padding: 3rem var(--container-padding) 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.app-logo {
    width: 32px;
    height: 32px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-logo svg {
    width: 100%;
    height: 100%;
    fill: var(--text-primary);
    display: block;
}

.app-title {
    font-family: 'Andale Mono', monospace;
    font-variant: small-caps;
    font-size: 1.5rem;
    line-height: 1.4;
    word-spacing: -0.4em;
    letter-spacing: 0.08em;
    text-transform: lowercase;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.app-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0;
    white-space: nowrap;
}

/* Main content — fills remaining space between header and footer */
.app-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Form section */
.app-form-section {
    max-width: 38rem;
    margin: 0 auto;
    padding: 2.5rem var(--container-padding) 0;
    width: 100%;
}

.url-input-group {
    display: flex;
    gap: 0.75rem;
    align-items: stretch;
}

.url-input {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: transparent;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 0.85rem 1rem;
    outline: none;
    word-spacing: -0.4em;
    transition: border-color 0.2s ease;
    width: 100%;
    flex: 1;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}

.url-input::placeholder {
    color: var(--text-inactive);
}

.url-input:focus {
    border-color: #666;
}

.url-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-summarize {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    padding: 0.85rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    word-spacing: -0.4em;
    transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    outline: none;
    background: #1a1a1a;
    border: 1px solid #444;
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    transform: translateZ(0);
}

.btn-summarize::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 100%
    );
    transform: translateX(-100%) skewX(-12deg);
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
}

.btn-summarize::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.1) 0%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 100%
    );
    border-radius: 6px;
    opacity: 0;
    transform: scale(0.85);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.btn-summarize:hover:not(:disabled)::before {
    transform: translateX(100%) skewX(-12deg);
}

.btn-summarize:active:not(:disabled)::after {
    opacity: 1;
    transform: scale(1);
    transition: all 0.08s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-summarize:hover:not(:disabled) {
    background: #252525;
    border-color: #555;
}

.btn-summarize:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Status / loading message */
.app-status {
    max-width: 38rem;
    margin: 1rem auto 0;
    padding: 0 var(--container-padding);
    width: 100%;
}

.status-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    word-spacing: 0.025em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-text.error {
    color: #e88;
}

/* Spinner */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 1.5px solid #444;
    border-top-color: #ccc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
    margin-right: 0.2rem;
}


/* Results section */
.app-results-section {
    max-width: 38rem;
    margin: 0.75rem auto 0;
    padding: 0 var(--container-padding);
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.app-results-section[hidden] {
    display: none;
}

.results-code-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    margin: 0;
}

.results-code-wrapper pre {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: auto;
}

/* Rendered markdown summary */
.summary-rendered {
    font-family: var(--font-body);
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-body);
    padding: 1.5rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: 2rem;
}

.summary-rendered h1 {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1.15rem;
    color: var(--text-primary);
    margin: 0 0 0.35rem;
    line-height: 1.4;
}

.summary-rendered h1 + p {
    margin-bottom: 1.25rem;
}

.summary-rendered h2 {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1.15rem;
    font-variant: small-caps;
    text-transform: lowercase;
    color: var(--text-primary);
    word-spacing: -0.175em;
    letter-spacing: 0.1em;
    margin: 1.75rem 0 0.75rem;
    line-height: 1.4;
}

.summary-rendered h3 {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin: 1.25rem 0 0.35rem;
}

.summary-rendered p {
    margin: 0.25rem 0 0.5rem;
}

.summary-rendered ul,
.summary-rendered ol {
    margin: 0.35rem 0 0.65rem 1.25rem;
    padding: 0;
}

.summary-rendered li {
    margin: 0.35rem 0;
}

.summary-rendered li > ul,
.summary-rendered li > ol {
    margin-top: 0.25rem;
    margin-bottom: 0.1rem;
}

.summary-rendered strong {
    color: var(--text-primary);
    font-weight: 600;
}

.summary-rendered a {
    color: var(--text-secondary);
    font-size: 0.8rem;
    display: inline-block;
    margin-bottom: 0.95rem;
    letter-spacing: 0.04em;
    transition: color 0.2s ease;
}

.summary-rendered a::after {
    display: none;
}

@media (hover: hover) {
    .summary-rendered a:hover {
        color: var(--text-primary);
    }
}

.summary-rendered code {
    font-size: 0.8em;
}

.summary-rendered pre {
    margin: 0.75rem 0;
    padding: 1rem;
    font-size: 0.8rem;
}

/* Ensure copy button tooltip label is correct for summary */
.results-code-wrapper .copy-button::before {
    content: 'Copy markdown';
}

.results-code-wrapper .copy-button.copied::before {
    content: 'Copied!';
}

.usage-counter {
    position: fixed;
    top: calc(1rem + 6px);
    right: 1.5rem;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-inactive);
    z-index: 10;
    text-align: right;
    max-width: 50vw;
}

.usage-counter:empty {
    display: none;
}

.summary-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0;
    padding: 1rem 1.5rem 0.5rem;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-inactive);
    border-top: 1px solid #1f1f1f;
    flex-shrink: 0;
}

.summary-meta:has(.model-badge:empty):has(.rate-limit-info:empty) {
    display: none;
}

.model-badge:empty,
.rate-limit-info:empty {
    display: none;
}

.model-badge:not(:empty) + .rate-limit-info:not(:empty)::before {
    content: '\2002\00B7\2002';
}

.summary-inline-meta {
    display: none;
}

@media (max-width: 768px) {
    .summary-inline-meta {
        display: block;
        font-family: 'IBM Plex Mono', monospace;
        font-size: 0.75rem;
        color: var(--text-inactive);
        margin-top: 1.5rem;
        padding-top: 1rem;
        border-top: 1px solid #1f1f1f;
    }
}

/* Footer spacing adjustment (app-specific) */
footer {
    padding: 1.25rem 0;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .summary-meta {
        display: none;
    }

    .usage-counter {
        font-size: 0.65rem;
        right: 1rem;
    }

    .app-header {
        padding-top: 1.5rem;
    }

    .app-title {
        font-size: 1.6rem;
    }

    .app-form-section {
        padding-top: 1.25rem;
    }

    .url-input-group {
        flex-direction: column;
        gap: 0.625rem;
    }

    /* Prevent iOS Safari from zooming in on input focus (threshold is 16px) */
    .url-input {
        font-size: 16px;
    }

    .btn-summarize {
        width: 100%;
    }

    footer {
        padding: 0.75rem 0 calc(0.75rem + env(safe-area-inset-bottom));
        margin-top: 0.5rem;
    }

    .summary-rendered {
        padding: 1rem;
        padding-bottom: 1.25rem;
    }
}

/* Info button */
.info-btn {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 100;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-inactive);
    transition: color var(--transition-base);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

@media (hover: hover) {
    .info-btn:hover {
        color: var(--text-secondary);
    }
}

.info-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    display: block;
}

/* Info modal overlay */
.info-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    padding-top: max(1.5rem, env(safe-area-inset-top));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.info-modal-overlay[hidden] {
    display: none;
}

/* Info modal */
.info-modal {
    position: relative;
    background: #111;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    padding: 2rem 2rem 2.5rem;
    max-width: 32rem;
    width: 100%;
    max-height: 85svh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.info-modal h2 {
    font-family: 'IBM Plex Mono', monospace;
    font-variant: small-caps;
    font-size: 1.1rem;
    text-transform: lowercase;
    word-spacing: -0.4em;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    margin-bottom: 1rem;
    padding-right: 2rem;
}

.info-modal h3 {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    margin: 1.5rem 0 0.5rem;
}

.info-modal p,
.info-modal ol {
    font-size: 0.85rem;
    color: var(--text-body);
    line-height: 1.7;
}

.info-modal ol {
    margin-left: 1.25rem;
    padding: 0;
}

.info-modal li {
    margin: 0.2rem 0;
}

.info-modal strong {
    color: var(--text-primary);
    font-weight: 600;
}

.info-modal a {
    color: var(--text-secondary);
    font-size: inherit;
    display: inline;
}

.info-modal a::after {
    display: none;
}

@media (hover: hover) {
    .info-modal a:hover {
        color: var(--text-primary);
    }
}

.info-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-inactive);
    transition: color var(--transition-base);
}

@media (hover: hover) {
    .info-modal-close:hover {
        color: var(--text-secondary);
    }
}

.info-modal-credit {
    margin-top: 1.75rem;
    padding-top: 1.25rem;
    border-top: 1px solid #1f1f1f;
    font-size: 0.75rem;
    color: var(--text-inactive);
}

.info-modal-close svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    display: block;
}

@media (max-width: 480px) {
    .info-modal {
        padding: 1.75rem 1.25rem 2.25rem;
    }
}

/* Visually hidden utility (a11y — visible to screen readers only) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link for a11y */
.skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.skip-link:focus {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: auto;
    height: auto;
    padding: 0.5rem 1rem;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 4px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.85rem;
    color: var(--text-primary);
    z-index: 9999;
    outline: none;
}
