:root {
  --bg: #eef7f9;
  --panel: rgba(251, 255, 255, 0.9);
  --panel-strong: #f9fdfe;
  --line: rgba(4, 137, 166, 0.16);
  --text: #14333b;
  --muted: #547078;
  --accent: #0489a6;
  --accent-dark: #036f87;
  --accent-soft: #dceff4;
  --signal: #bf1e2e;
  --ok: #276749;
  --error: #a12633;
  --busy: #7a5c13;
  --shadow: 0 24px 50px rgba(12, 92, 111, 0.12);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(4, 137, 166, 0.16), transparent 26%),
    radial-gradient(circle at bottom right, rgba(191, 30, 46, 0.08), transparent 18%),
    linear-gradient(180deg, #f8fcfd 0%, var(--bg) 100%);
}

.shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 14px 0 40px;
}

.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  margin-bottom: 14px;
  border: 1px solid rgba(4, 137, 166, 0.18);
  background:
    linear-gradient(135deg, rgba(231, 246, 249, 0.98) 0%, rgba(242, 251, 253, 0.94) 62%, rgba(255, 255, 255, 0.92) 100%);
  backdrop-filter: blur(12px);
  border-radius: 18px;
  box-shadow:
    0 20px 44px rgba(12, 92, 111, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.appbar-copy {
  min-width: 0;
}

.appbar-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.howa-logo {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid rgba(4, 137, 166, 0.16);
  box-shadow: 0 10px 24px rgba(12, 92, 111, 0.14);
  flex: 0 0 auto;
}

.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.toggle-label {
  font-size: 0.74rem;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.segmented {
  display: inline-flex;
  border: 1px solid rgba(81, 62, 39, 0.12);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.64);
  padding: 3px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.78rem;
  border-radius: 999px;
  transition: background 120ms ease, color 120ms ease, transform 120ms ease;
}

.segmented input:checked + span {
  background: linear-gradient(180deg, #0a95b3 0%, #047f9a 100%);
  color: #fff;
  box-shadow: 0 4px 10px rgba(4, 137, 166, 0.2);
}

.segmented label:hover span {
  transform: translateY(-1px);
}

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

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2.8vw, 2.3rem);
  line-height: 1.05;
  max-width: none;
}

.appbar p {
  margin: 6px 0 0;
  line-height: 1.4;
  color: var(--muted);
  font-size: 0.98rem;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.field {
  display: block;
  margin-bottom: 18px;
}

.field span {
  display: block;
  margin-bottom: 8px;
  font-size: 0.98rem;
}

input[type="file"],
input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 14px 16px;
  font: inherit;
}

input[type="file"] {
  display: none;
}

.dropzone {
  border: 1.5px dashed rgba(4, 137, 166, 0.28);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.84) 0%, rgba(238,247,249,0.94) 100%);
  padding: 20px;
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone[data-drag="on"] {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(248,253,254,0.98) 0%, rgba(226,243,247,0.98) 100%);
  transform: translateY(-1px);
  outline: none;
}

.dropzone-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.dropzone-copy strong {
  font-size: 1rem;
}

.dropzone-copy span,
.file-list {
  color: var(--muted);
}

.file-list {
  border-top: 1px solid rgba(81, 62, 39, 0.1);
  padding-top: 12px;
  font-size: 0.92rem;
  line-height: 1.45;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.actions,
.panel-head,
.source-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(180deg, #0a95b3 0%, #047f9a 100%);
  color: white;
  cursor: pointer;
  font-size: 0.98rem;
  box-shadow:
    0 10px 24px rgba(4, 137, 166, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

button:hover:not([disabled]) {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #0ca0bf 0%, #0589a6 100%);
  box-shadow:
    0 14px 28px rgba(4, 137, 166, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

button:active:not([disabled]) {
  transform: translateY(0);
  background: linear-gradient(180deg, #067a94 0%, #046c84 100%);
}

button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.status {
  margin: 0;
  color: var(--muted);
}

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

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

.status[data-tone="busy"] {
  color: var(--busy);
}

.result-grid {
  display: block;
  margin-top: 20px;
}

.output {
  margin-top: 14px;
}

.email-preview {
  min-height: 220px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(247, 252, 253, 0.98) 0%, rgba(232, 245, 248, 0.98) 100%);
  border: 1px solid rgba(4, 137, 166, 0.18);
  padding: 18px;
  font-size: 0.98rem;
  line-height: 1.6;
  white-space: normal;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.email-preview p {
  margin: 0 0 1em;
}

.email-preview p:last-child {
  margin-bottom: 0;
}

.source-head h3,
.panel-head h2,
.output h2 {
  margin: 0;
}

.sources-empty {
  color: var(--muted);
  padding: 8px 0;
}

@media (max-width: 900px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 10px;
  }

  .appbar,
  .panel {
    padding: 18px;
  }

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

  .appbar-side {
    width: 100%;
    justify-content: space-between;
  }

  .howa-logo {
    width: 70px;
    height: 70px;
  }

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

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

  button {
    width: 100%;
  }
}
