:root {
  --bg: #f4f0e6;
  --paper: #fffdf8;
  --ink: #1f1d1a;
  --muted: #746d60;
  --accent: #efb51a;
  --accent-strong: #d88d00;
  --line: rgba(31, 29, 26, 0.12);
  --ok: #205c46;
  --error: #9c2f2f;
  --footer-height: 84px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: calc(var(--footer-height) + 18px);
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(239, 181, 26, 0.2), transparent 26%),
    linear-gradient(180deg, #efe3c1, var(--bg));
}

.shell {
  width: min(1180px, calc(100% - 24px));
  margin: 22px auto 30px;
  display: grid;
  gap: 18px;
}

.hero,
.history-panel,
.latest-panel {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(31, 29, 26, 0.08);
}

.hero {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.hero-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.hero-logo {
  width: auto;
  height: clamp(44px, 6vw, 68px);
  max-width: min(32vw, 240px);
  object-fit: contain;
  flex-shrink: 0;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  font-size: clamp(1.9rem, 4vw, 3rem);
  line-height: 1.1;
}

.language-control {
  display: grid;
  gap: 8px;
  min-width: min(320px, 100%);
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.95rem;
}

select,
button {
  font: inherit;
}

select {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
  padding: 12px 14px;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  background: #2e4d53;
  color: white;
  cursor: pointer;
}

button[hidden] {
  display: none;
}

.status-panel {
  display: grid;
  gap: 14px;
  align-items: start;
  justify-items: start;
}

.connection-status {
  margin: 0;
  font-weight: 700;
}

.connection-status[data-kind="success"] {
  color: var(--ok);
}

.connection-status[data-kind="error"] {
  color: var(--error);
}

.is-session-error .status-panel {
  width: min(680px, 100%);
  justify-self: center;
  justify-items: center;
  padding: 28px;
  text-align: center;
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(31, 29, 26, 0.08);
}

.viewer-grid {
  display: grid;
  gap: 18px;
}

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 18px;
  background: #015c82;
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 26px rgba(31, 29, 26, 0.08);
  backdrop-filter: blur(8px);
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.footer-brand:hover {
  color: #2e4d53;
}

.footer-logo {
  width: auto;
  height: 100%;
  object-fit: contain;
}

.history-panel,
.latest-panel {
  padding: 20px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 14px;
}

.panel-head span {
  color: var(--muted);
  font-size: 0.9rem;
}

.history-text {
  min-height: 360px;
  max-height: 52vh;
  overflow: auto;
  white-space: pre-wrap;
  padding: 4px 6px 4px 0;
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.5;
}

.latest-block {
  position: relative;
  min-height: 160px;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffe784, #ffd84d);
  padding: 54px 24px 24px;
  font-size: clamp(1.4rem, 4vw, 2.6rem);
  line-height: 1.35;
  font-weight: 700;
}

.latest-text {
  max-width: 100%;
}

.tts-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.tts-toggle {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(31, 29, 26, 0.18);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.88);
  color: #3f3829;
  box-shadow: 0 8px 18px rgba(31, 29, 26, 0.14);
}

.tts-rate {
  width: auto;
  min-width: 78px;
  height: 42px;
  padding: 0 28px 0 12px;
  border-color: rgba(31, 29, 26, 0.18);
  border-radius: 999px;
  background-color: rgba(255, 253, 248, 0.88);
  color: #3f3829;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(31, 29, 26, 0.14);
}

.tts-rate:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.tts-toggle:hover {
  background: white;
}

.tts-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.tts-icon {
  width: 22px;
  height: 22px;
}

.tts-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tts-icon--on {
  display: none;
}

.tts-toggle.is-active {
  background: #2e4d53;
  color: white;
}

.tts-toggle.is-active .tts-icon--off {
  display: none;
}

.tts-toggle.is-active .tts-icon--on {
  display: block;
}

@media (max-width: 720px) {
  :root {
    --footer-height: 96px;
  }

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

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

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .latest-block {
    min-height: 120px;
  }

  .hero-brand {
    width: 100%;
    justify-content: flex-start;
  }

  .app-footer {
    padding: 12px 14px;
  }

  .footer-brand {
    gap: 10px;
    text-align: center;
    font-size: 0.95rem;
  }

  .footer-logo {
    height: 100%;
  }
}
