:root {
  color-scheme: light;
  --primary: #1e3a8a;
  --primary-hover: #172e6d;
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface-soft: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #1f2937;
  --muted: #6b7280;
  --muted-soft: #9ca3af;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  --page-padding: clamp(24px, 3vw, 64px);
  --layout-gap: clamp(20px, 2vw, 36px);
  --sidebar-width: clamp(320px, 22vw, 400px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.3;
}

.app-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  column-gap: var(--layout-gap);
  width: 100%;
  min-height: 100vh;
  padding: 0 var(--page-padding);
}

.main-content {
  min-width: 0;
  padding: 40px 0;
  overflow-y: auto;
}

.main-header {
  margin-bottom: 32px;
}

.logo {
  color: var(--primary);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.1;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.input-card,
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.input-card {
  margin-bottom: 24px;
  padding: 20px;
}

.input-header,
.input-footer,
.result-header,
.sidebar-header,
.result-tools,
.history-tools {
  display: flex;
  align-items: center;
}

.input-header,
.result-header,
.sidebar-header {
  justify-content: space-between;
  gap: 12px;
}

label,
.word-count,
#status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

textarea {
  display: block;
  width: 100%;
  min-height: 132px;
  margin-top: 12px;
  border: 0;
  outline: 0;
  resize: vertical;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
}

textarea::placeholder,
input::placeholder {
  color: var(--muted-soft);
}

.input-card:focus-within,
.result-card:focus-within {
  border-color: var(--border-strong);
}

.input-footer {
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--surface-soft);
}

button {
  border: 0;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 6px;
  padding: 0 18px;
  font-weight: 650;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(30, 58, 138, 0.18);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.result-card {
  min-height: 220px;
  padding: 24px;
}

.result-header {
  margin-bottom: 18px;
}

.result-header h2,
.sidebar-header h2 {
  font-size: 16px;
  font-weight: 750;
}

.result-tools,
.history-tools {
  gap: 8px;
}

.btn-icon,
.export-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--primary);
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
}

.btn-icon.small {
  width: 32px;
  height: 32px;
}

.btn-icon:hover,
.export-link:hover,
.history-actions button:hover {
  border-color: var(--border-strong);
  background: var(--surface-soft);
}

.export-link {
  min-height: 32px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.result {
  display: grid;
  gap: 16px;
  color: var(--text);
  line-height: 1.75;
}

.result.empty {
  display: flex;
  min-height: 120px;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted-soft);
  text-align: center;
}

.result.error {
  display: block;
  color: var(--danger);
}

.edit-form {
  display: grid;
  gap: 14px;
}

.edit-form label {
  display: grid;
  gap: 8px;
}

.edit-form input,
.edit-form textarea {
  width: 100%;
  min-height: 40px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 11px;
  background: var(--surface);
}

.edit-form textarea {
  min-height: 120px;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-soft);
}

.result-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.result-title h3 {
  font-size: 28px;
  font-weight: 750;
  line-height: 1.18;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #eff6ff;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.pronunciation {
  color: var(--muted);
  font-weight: 650;
}

.examples {
  display: grid;
  gap: 14px;
  margin: 0;
  border-left: 3px solid var(--border);
  padding: 0 0 0 16px;
  list-style: none;
}

.examples strong {
  display: block;
  font-weight: 700;
}

.examples span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.history-sidebar {
  display: flex;
  min-width: 0;
  max-height: 100vh;
  flex-direction: column;
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.filter-bar {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.search-label {
  display: block;
  margin-bottom: 8px;
}

.history-search {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 11px;
  background: var(--surface);
  color: var(--text);
  outline: 0;
}

.history-search:focus {
  border-color: var(--primary);
}

.type-filter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.type-filter button {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.type-filter button:hover {
  background: var(--surface-soft);
}

.type-filter button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.history-list {
  flex: 1;
  overflow-y: auto;
}

.history-item {
  display: grid;
  gap: 9px;
  width: 100%;
  min-height: auto;
  border: 0;
  border-bottom: 1px solid var(--surface-soft);
  border-radius: 0;
  padding: 16px;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 160ms ease;
}

.history-item:hover {
  background: var(--bg);
}

.history-item strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.history-actions {
  display: flex;
  gap: 12px;
  opacity: 0;
  transition: opacity 160ms ease;
}

.history-item:hover .history-actions,
.history-item:focus-within .history-actions {
  opacity: 1;
}

.history-actions button {
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  padding: 0;
  background: transparent;
  color: var(--primary);
  font-size: 12px;
  font-weight: 650;
}

.history-actions .danger-button {
  color: var(--danger);
}

.history-actions .danger-button:hover {
  background: transparent;
  color: #991b1b;
}

.empty-state {
  padding: 18px 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

@media (max-width: 900px) {
  .app-container {
    grid-template-columns: 1fr;
    width: 100%;
    padding: 0;
  }

  .main-content {
    padding: 28px 20px;
  }

  .history-sidebar {
    max-height: none;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .history-list {
    max-height: 420px;
  }
}

@media (max-width: 560px) {
  .main-content {
    padding: 22px 14px;
  }

  .input-footer {
    align-items: stretch;
  }

  .btn-primary {
    width: 100%;
  }

  .result-header,
  .sidebar-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .history-tools,
  .result-tools {
    width: 100%;
  }

  .history-tools {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
