:root {
  --bg: #e9f3ff;
  --bg-strong: #dcecff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(247, 251, 255, 0.96);
  --panel-edge: #c3d8f0;
  --text: #173553;
  --muted: #6c84a1;
  --accent: #4f8fd8;
  --accent-strong: #2f72c8;
  --accent-dim: rgba(79, 143, 216, 0.14);
  --accent-dim-strong: rgba(79, 143, 216, 0.22);
  --shadow: 0 18px 44px rgba(55, 96, 146, 0.12);
  --warn-bg: rgba(255, 206, 107, 0.22);
  --warn-border: rgba(214, 157, 34, 0.38);
  --warn-text: #7a4d00;
  --danger: #b42318;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background:
    radial-gradient(circle at top left, rgba(113, 171, 238, 0.26), transparent 32%),
    radial-gradient(circle at bottom right, rgba(119, 196, 224, 0.22), transparent 28%),
    linear-gradient(180deg, #eef6ff 0%, #dfeeff 100%);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px 36px;
}

body::before,
body::after {
  content: "";
  position: fixed;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  filter: blur(28px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}

body::before {
  top: -80px;
  left: -60px;
  background: rgba(132, 185, 244, 0.42);
}

body::after {
  right: -90px;
  bottom: -70px;
  background: rgba(124, 203, 225, 0.35);
}

header,
main {
  width: 100%;
  max-width: 760px;
  position: relative;
  z-index: 1;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

h1 span { color: var(--accent-strong); }

.hero-copy {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 480px;
  line-height: 1.45;
}

.status {
  min-width: 150px;
  text-align: right;
  font-size: 0.84rem;
  color: var(--accent-strong);
  min-height: 1.2em;
  padding-top: 8px;
}

.warning-banner {
  width: 100%;
  max-width: 760px;
  margin-bottom: 14px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  font-size: 0.84rem;
  line-height: 1.45;
  position: relative;
  z-index: 1;
}

.warning-banner[hidden] { display: none; }

main {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.controls {
  display: grid;
  gap: 12px;
}

.control-card,
.pane {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.control-card { padding: 16px; }

.control-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.control-head-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.control-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.control-note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  text-align: right;
}

.engine,
.tone-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.eng-btn,
.tone-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.eng-btn:hover,
.tone-btn:hover {
  transform: translateY(-1px);
  color: var(--text);
  border-color: rgba(79, 143, 216, 0.26);
  background: rgba(255, 255, 255, 0.8);
}

.eng-btn.active,
.tone-btn.active {
  color: var(--accent-strong);
  background: var(--accent-dim);
  border-color: rgba(79, 143, 216, 0.34);
  box-shadow: inset 0 0 0 1px rgba(79, 143, 216, 0.08);
}

.tone-btn {
  flex: 1 1 200px;
  text-align: left;
  border-radius: 18px;
  padding: 12px 14px;
  min-height: 54px;
}

.pane {
  padding: 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pane:focus-within {
  border-color: rgba(79, 143, 216, 0.46);
  box-shadow: 0 18px 44px rgba(55, 96, 146, 0.18);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.char-counter {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.char-counter.over {
  color: var(--danger);
}

textarea {
  width: 100%;
  min-height: 180px;
  background: transparent;
  border: none;
  outline: none;
  resize: vertical;
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.62;
  caret-color: var(--accent-strong);
}

textarea::placeholder { color: var(--muted); }

textarea:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
}

.direction {
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  background: var(--accent-dim);
  border: 1px solid rgba(79, 143, 216, 0.24);
  border-radius: 999px;
  padding: 9px 20px;
  transition: transform 0.25s ease;
}

.direction.flip { transform: rotateX(360deg); }

.swap-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(79, 143, 216, 0.24);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
}

.swap-btn:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(79, 143, 216, 0.36);
}

.output-pane { position: relative; }

#output {
  min-height: 180px;
  font-size: 1.05rem;
  line-height: 1.62;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
}

#output.empty { color: var(--muted); }

.source-badge,
.cloud-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 6px 12px;
}

.source-badge {
  color: var(--accent-strong);
  background: rgba(79, 143, 216, 0.1);
  border: 1px solid rgba(79, 143, 216, 0.24);
}

.cloud-badge {
  color: #0f5132;
  background: rgba(117, 183, 152, 0.16);
  border: 1px solid rgba(71, 140, 104, 0.28);
}

.source-badge::before,
.cloud-badge::before,
.language-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.source-badge::before { background: var(--accent); }
.cloud-badge::before { background: #47986a; }

.source-badge[hidden],
.cloud-badge[hidden],
.language-badge[hidden] { display: none; }

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.language-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #7a4d00;
  background: rgba(255, 206, 107, 0.18);
  border: 1px solid rgba(214, 157, 34, 0.32);
  border-radius: 999px;
  padding: 6px 12px;
}

.language-badge::before { background: #d69d22; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.toolbar button,
.secondary-btn,
.swap-btn {
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.toolbar button {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 11px 18px;
  cursor: pointer;
}

.toolbar button:hover {
  transform: translateY(-1px);
  border-color: rgba(79, 143, 216, 0.36);
  background: rgba(255, 255, 255, 0.98);
}

.secondary-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-strong);
  background: rgba(79, 143, 216, 0.1);
  border: 1px solid rgba(79, 143, 216, 0.24);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
}

.secondary-btn:hover {
  transform: translateY(-1px);
  background: rgba(79, 143, 216, 0.16);
  border-color: rgba(79, 143, 216, 0.34);
}

.toolbar button:focus-visible,
.eng-btn:focus-visible,
.tone-btn:focus-visible,
.secondary-btn:focus-visible,
.swap-btn:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

button.copied {
  background: var(--accent-dim-strong);
  border-color: rgba(79, 143, 216, 0.42);
  color: var(--accent-strong);
}

.model-select {
  width: 100%;
  margin-top: 10px;
  font-family: inherit;
  font-size: 0.88rem;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
}

.history-panel {
  margin-top: 4px;
}

.history-list {
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.history-item {
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.84rem;
  line-height: 1.35;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
  cursor: pointer;
}

.history-item:hover {
  border-color: rgba(79, 143, 216, 0.34);
  background: rgba(255, 255, 255, 0.88);
}

.history-meta {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  text-align: center;
  padding: 2px 8px 0;
}

#turnstileContainer {
  display: flex;
  justify-content: center;
  min-height: 0;
}

#turnstileContainer:not(:empty) {
  min-height: 65px;
  margin-top: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .direction,
  .direction.flip,
  .eng-btn,
  .tone-btn,
  .toolbar button {
    transition: none;
    transform: none;
  }
}

@media (max-width: 720px) {
  header,
  .control-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .status,
  .control-note {
    text-align: left;
    min-width: 0;
    padding-top: 0;
  }
}

@media (max-width: 560px) {
  body { padding: 18px 12px 28px; }
  h1 { font-size: 1.6rem; }

  .pane,
  .control-card {
    border-radius: 18px;
    padding: 14px;
  }

  .toolbar button {
    flex: 1 1 140px;
    justify-content: center;
  }

  textarea,
  #output {
    min-height: 160px;
  }
}
