:root {
    color-scheme: light;
    --bg: #edf2f7;
    --panel: #ffffff;
    --panel-border: #d7dee7;
    --text: #17202a;
    --muted: #5d6b7a;
    --primary: #1677ff;
    --primary-hover: #0e63d6;
    --danger: #db3f59;
    --danger-hover: #bf3149;
    --surface: #f6f8fb;
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
    --radius: 20px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: 'Segoe UI', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background:
        radial-gradient(circle at top, rgba(22, 119, 255, 0.12), transparent 28%),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
    color: var(--text);
}

body {
    display: grid;
    place-items: center;
    padding: 24px;
}

.app-shell {
    width: min(100%, 1180px);
}

.app-footer {
    padding: 18px 6px 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
}

.app-footer p {
    margin: 0;
}

.app-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.app-footer a:hover,
.app-footer a:focus-visible {
    text-decoration: underline;
}

.layout-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 360px);
    gap: 24px;
    align-items: start;
}

.app-card {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.sidebar-card {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
    display: grid;
    gap: 20px;
    max-height: min(80vh, 920px);
    overflow: auto;
}

.sidebar-section {
    display: grid;
    gap: 12px;
}

.sidebar-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.sidebar-subheading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.sidebar-eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar-heading h2 {
    margin: 0;
    font-size: 1.1rem;
}

.sidebar-subheading h3 {
    margin: 0;
    font-size: 1rem;
}

.sidebar-meta {
    padding: 7px 10px;
    border-radius: 999px;
    background: #eef3f8;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 14px;
  flex: 0 0 auto;
}

.eyebrow {
    margin: 0 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--primary);
}

h1 {
    margin: 0;
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    line-height: 1.1;
}

.status-wrap {
    display: grid;
    gap: 6px;
    justify-items: end;
}

.status-label {
    font-size: 0.84rem;
    color: var(--muted);
}

.status-chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 700;
    background: #e7edf3;
    color: #234;
}

.status-ready,
.status-ended {
    background: #e8f3ea;
    color: #20613a;
}

.status-speaking {
    background: #e8f0ff;
    color: #154ca8;
}

.status-paused {
    background: #fff3dd;
    color: #8c5a05;
}

.status-error {
    background: #ffe5ea;
    color: #a2263e;
}

.message {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid #f2c6d0;
    background: #fff1f4;
    color: #8b2237;
}

.favorites-panel {
    display: grid;
    gap: 12px;
    margin-bottom: 22px;
    padding: 16px;
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    background: linear-gradient(180deg, #f9fbff 0%, #f3f7fb 100%);
}

.favorites-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.favorites-heading h2 {
    margin: 0;
    font-size: 1rem;
}

.field {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
}

label {
    font-size: 0.95rem;
    font-weight: 700;
}

textarea,
select,
button,
input[type='range'] {
    font: inherit;
}

textarea,
select {
    width: 100%;
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
}

textarea {
    min-height: 180px;
    padding: 14px 16px;
    resize: vertical;
    line-height: 1.55;
}

select {
    min-height: 48px;
    padding: 0 14px;
}

textarea:focus,
select:focus,
button:focus,
input[type='range']:focus {
    outline: 3px solid rgba(22, 119, 255, 0.2);
    outline-offset: 2px;
}

.help-text {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.range-field {
    padding: 14px;
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    background: var(--surface);
}

.range-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

output {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

input[type='range'] {
    width: 100%;
    margin: 4px 0 0;
    accent-color: var(--primary);
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
}

.history-list {
    display: grid;
    gap: 10px;
}

#favorites-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(140px, 180px);
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
}

#favorites-list .history-item,
#favorites-list .empty-state {
    min-height: 100%;
}

#favorites-list .history-item {
    gap: 8px;
    padding: 10px;
}

#favorites-list .history-preview {
    font-size: 0.82rem;
    line-height: 1.3;
    -webkit-line-clamp: 4;
}

#favorites-list .icon-button {
    min-height: 32px;
    min-width: 32px;
    padding: 0 10px;
    border-radius: 10px;
}

.history-item,
.empty-state {
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    background: var(--surface);
}

.history-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 12px;
    align-items: start;
}

.history-main {
    display: grid;
    gap: 6px;
    text-align: left;
    width: 100%;
    min-width: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    border: 0;
    border-radius: 10px;
    min-height: 0;
}

.history-main:hover:not(:disabled) {
    background: transparent;
    transform: none;
}

.history-main-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.history-preview {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-actions {
    display: flex;
    gap: 8px;
}

.icon-button {
    min-height: 38px;
    min-width: 38px;
    padding: 0 12px;
    border-radius: 12px;
    background: #eaf0f6;
    color: #223042;
}

.icon-button:hover:not(:disabled) {
    background: #d7e1eb;
}

.icon-button-active {
    background: #ffe7ef;
    color: #a2263e;
}

.icon-button-active:hover:not(:disabled) {
    background: #ffd4e2;
}

.empty-state {
    padding: 16px;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.45;
}

button {
    min-height: 46px;
    padding: 0 18px;
    border: 0;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    transition:
        background-color 140ms ease,
        transform 140ms ease;
}

button:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.button-muted {
    background: #dce4ec;
    color: #223042;
}

.button-muted:hover:not(:disabled) {
    background: #cbd6e1;
}

#stop-btn {
    background: var(--danger);
}

#stop-btn:hover:not(:disabled) {
    background: var(--danger-hover);
}

@media (max-width: 720px) {
    .layout-grid {
        grid-template-columns: 1fr;
    }

    .app-card {
        padding: 20px;
    }

    .sidebar-card {
        padding: 18px;
        max-height: none;
    }

  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .brand-lockup {
    align-items: flex-start;
  }

    .favorites-heading {
        flex-direction: column;
        align-items: flex-start;
    }

    .status-wrap {
        justify-items: start;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .button-row button {
        flex: 1 1 calc(50% - 12px);
    }
}

@media (max-width: 480px) {
    body {
        padding: 14px;
    }

    textarea {
        height: 80px !important;
        min-height: 80px !important;
    }

    #favorites-list {
        grid-auto-flow: row;
        grid-auto-columns: unset;
        overflow-x: visible;
    }

    .history-item {
        grid-template-columns: 1fr;
    }

    .history-actions {
        justify-content: flex-end;
    }

    .button-row button {
        flex-basis: 100%;
    }
}
