:root {
  --md-sys-color-primary: #0062a1;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #cfe5ff;
  --md-sys-color-on-primary-container: #001d35;
  --md-sys-color-secondary-container: #dce3f0;
  --md-sys-color-background: #f5f8fc;
  --md-sys-color-surface: #ffffff;
  --md-sys-color-surface-variant: #eef2f8;
  --md-sys-color-on-surface: #1a1c20;
  --md-sys-color-on-surface-variant: #42474e;
  --md-sys-color-outline: #72787e;
  --md-sys-color-outline-variant: #c2c7cf;
  --nav-width: 220px;
  --nav-bg: #e8f0fb;
  /* checkbox fix */
  --md-checkbox-outline-color: #72787e;
  --md-checkbox-selected-container-color: #0062a1;

  /* ── md-filled-select tokens (light) ── */
  --md-filled-select-text-field-container-color: #eef2f8;
  --md-filled-select-text-field-input-text-color: #1a1c20;
  --md-filled-select-text-field-label-text-color: #42474e;
  --md-filled-select-text-field-trailing-icon-color: #42474e;
  --md-filled-select-text-field-active-indicator-color: #0062a1;
  --md-filled-select-text-field-focus-active-indicator-color: #0062a1;
  --md-filled-select-text-field-focus-label-text-color: #0062a1;
  --md-filled-select-text-field-hover-active-indicator-color: #42474e;
  /* menu/listbox */
  --md-menu-container-color: #ffffff;
  --md-list-item-label-text-color: #1a1c20;
  --md-select-option-selected-container-color: #cfe5ff;

  /* ── md-outlined-text-field tokens (light) ── */
  --md-outlined-text-field-container-color: #ffffff;
  --md-outlined-text-field-input-text-color: #1a1c20;
  --md-outlined-text-field-label-text-color: #42474e;
  --md-outlined-text-field-outline-color: #72787e;
  --md-outlined-text-field-focus-outline-color: #0062a1;
  --md-outlined-text-field-focus-label-text-color: #0062a1;
  --md-outlined-text-field-hover-outline-color: #1a1c20;
}

:root[data-theme="dark"] {
  --md-sys-color-primary: #9ecbff;
  --md-sys-color-on-primary: #003257;
  --md-sys-color-primary-container: #004a79;
  --md-sys-color-on-primary-container: #d2e4ff;
  --md-sys-color-secondary-container: #2e3441;
  --md-sys-color-background: #000000;
  --md-sys-color-surface: #0f1114;
  --md-sys-color-surface-variant: #181b1f;
  --md-sys-color-on-surface: #e2e2e6;
  --md-sys-color-on-surface-variant: #a8adb5;
  --md-sys-color-outline: #8c9199;
  --md-sys-color-outline-variant: #2e3238;
  --nav-bg: #080a0c;

  /* checkbox dark mode fix */
  --md-checkbox-outline-color: #8c9199;
  --md-checkbox-selected-container-color: #9ecbff;
  --md-checkbox-selected-icon-color: #003257;
  --md-checkbox-unselected-outline-color: #8c9199;
  --md-checkbox-unselected-hover-outline-color: #c4c9d0;
  --md-checkbox-container-color: transparent;
  --md-checkbox-unselected-pressed-outline-color: #8c9199;

  /* ── md-filled-select tokens (dark) ── */
  --md-filled-select-text-field-container-color: #181b1f;
  --md-filled-select-text-field-input-text-color: #e2e2e6;
  --md-filled-select-text-field-label-text-color: #a8adb5;
  --md-filled-select-text-field-trailing-icon-color: #a8adb5;
  --md-filled-select-text-field-active-indicator-color: #9ecbff;
  --md-filled-select-text-field-focus-active-indicator-color: #9ecbff;
  --md-filled-select-text-field-focus-label-text-color: #9ecbff;
  --md-filled-select-text-field-hover-active-indicator-color: #e2e2e6;
  /* menu/listbox */
  --md-menu-container-color: #1e2126;
  --md-list-item-label-text-color: #e2e2e6;
  --md-select-option-selected-container-color: #004a79;

  /* ── md-outlined-text-field tokens (dark) ── */
  --md-outlined-text-field-container-color: #0f1114;
  --md-outlined-text-field-input-text-color: #e2e2e6;
  --md-outlined-text-field-label-text-color: #a8adb5;
  --md-outlined-text-field-outline-color: #8c9199;
  --md-outlined-text-field-focus-outline-color: #9ecbff;
  --md-outlined-text-field-focus-label-text-color: #9ecbff;
  --md-outlined-text-field-hover-outline-color: #e2e2e6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Sans SC", "Roboto", sans-serif;
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  min-height: 100dvh;
  display: flex;
}

/* No background gradient in dark mode */
.page-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

:root:not([data-theme="dark"]) .page-bg {
  background:
    radial-gradient(ellipse at 5% 10%, color-mix(in srgb, var(--md-sys-color-primary) 10%, transparent), transparent 50%),
    radial-gradient(ellipse at 95% 90%, color-mix(in srgb, var(--md-sys-color-primary-container) 40%, transparent), transparent 45%);
}

/* ── Navigation Rail ── */
.nav-rail {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--nav-width);
  background: var(--nav-bg);
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  z-index: 100;
  border-right: 1px solid var(--md-sys-color-outline-variant);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 20px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  margin-bottom: 8px;
}

.nav-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  /* make svg inherit theme color in light/dark */
  filter: none;
}

:root[data-theme="dark"] .nav-logo {
  filter: invert(1) brightness(1.5) hue-rotate(180deg) saturate(0.6);
}

.nav-brand-text {
  font-size: 1rem;
  font-weight: 700;
  color: var(--md-sys-color-primary);
  white-space: nowrap;
}

.nav-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  border-radius: 50px;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
  color: var(--md-sys-color-primary);
}

.nav-item.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-primary);
  font-weight: 700;
}

.nav-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.nav-label { white-space: nowrap; }

/* ── Main wrap ── */
.main-wrap {
  margin-left: var(--nav-width);
  flex: 1;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

/* ── Page system ── */
.page {
  display: none;
  padding: 32px;
  max-width: 1000px;
  min-height: 100dvh;
}

.page.active { display: block; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--md-sys-color-on-surface);
  line-height: 1.2;
}

/* header-actions: make buttons taller */
.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.header-actions md-outlined-button {
  --md-outlined-button-container-height: 40px;
  min-width: 88px;
}

/* ── Cards ── */
.card {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 20px;
  padding: 16px;
}

.card-flat {
  background: var(--md-sys-color-surface-variant);
  border-radius: 16px;
  padding: 12px 16px;
}

/* ── Translate Page ── */
.translate-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lang-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lang-bar md-filled-select {
  flex: 1;
}

.swap-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent);
  border-radius: 50%;
  cursor: pointer;
  color: var(--md-sys-color-primary);
  flex-shrink: 0;
  transition: background 0.15s, transform 0.2s;
  position: relative;
  overflow: hidden;
}

.swap-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  transform: scale(0);
  transition: transform 0.4s cubic-bezier(.2,0,.0,1), opacity 0.4s;
  pointer-events: none;
}

.swap-btn:active::after {
  transform: scale(2.5);
  opacity: 0.16;
  transition: transform 0s, opacity 0s;
}

.swap-btn:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 20%, transparent);
  transform: rotate(180deg);
}

.swap-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  position: relative;
  z-index: 1;
}

.text-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.text-panel {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.panel-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: color-mix(in srgb, var(--md-sys-color-outline) 15%, transparent);
  color: var(--md-sys-color-on-surface);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.text-panel textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 14px;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  min-height: 220px;
}

.text-panel textarea::placeholder {
  color: var(--md-sys-color-outline);
}

.result-panel {
  background: color-mix(in srgb, var(--md-sys-color-primary-container) 20%, var(--md-sys-color-surface));
  position: relative;
}

/* Loader animation — inline in footer */
.loader {
  height: 18px;
  width: 18px;
  border: 2.5px solid color-mix(in srgb, var(--md-sys-color-primary) 25%, transparent);
  border-top-color: var(--md-sys-color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  letter-spacing: 0.04em;
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 8px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  min-height: 36px;
}

.panel-footer.right { justify-content: flex-end; }

/* Loading indicator — now inline in footer */
.translate-loading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.translate-loading[hidden] { display: none; }

.char-count {
  font-size: 0.78rem;
  color: var(--md-sys-color-outline);
}

.model-tag {
  font-size: 0.75rem;
  color: var(--md-sys-color-primary);
  font-weight: 500;
}

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

.actions-left {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Widen context and translate buttons */
#contextBtn {
  --md-outlined-button-container-height: 44px;
  min-width: 100px;
}

.translate-btn {
  --md-filled-button-container-height: 44px;
  min-width: 120px;
}

/* Provider chips */
.provider-chips {
  display: flex;
  gap: 8px;
}

.provider-chip {
  padding: 8px 20px;
  border: 2px solid var(--md-sys-color-outline-variant);
  border-radius: 50px;
  background: transparent;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.provider-chip:hover {
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}

.provider-chip.active {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* Refresh models button */
.refresh-models-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-primary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

.refresh-models-btn:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 10%, transparent);
}

.refresh-models-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.refresh-models-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── History Page ── */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--md-sys-color-on-surface-variant);
}

.history-empty svg {
  width: 48px;
  height: 48px;
  fill: var(--md-sys-color-outline);
  margin-bottom: 12px;
  display: block;
  margin-inline: auto;
}

.history-item {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 16px;
  padding: 14px 16px;
  transition: border-color 0.15s;
}

.history-item:hover {
  border-color: color-mix(in srgb, var(--md-sys-color-primary) 40%, transparent);
}

.history-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 10px;
}

.history-meta-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-chip {
  background: color-mix(in srgb, var(--md-sys-color-primary-container) 60%, transparent);
  color: var(--md-sys-color-on-primary-container);
  border-radius: 50px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 500;
}

.history-text {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.history-block {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--md-sys-color-surface-variant);
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--md-sys-color-on-surface);
}

.history-block-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--md-sys-color-outline);
  margin-bottom: 4px;
}

.history-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* ── Settings Page ── */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settings-group-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--md-sys-color-primary);
  margin-bottom: 8px;
  padding-left: 4px;
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 0;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.setting-row:first-child { padding-top: 4px; }
.setting-row:last-child { border-bottom: none; padding-bottom: 4px; }

.setting-name {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 2px;
}

.setting-desc {
  font-size: 0.82rem;
  color: var(--md-sys-color-on-surface-variant);
}

.theme-chips {
  display: flex;
  gap: 8px;
}

.theme-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  border: 2px solid var(--md-sys-color-outline-variant);
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.theme-chip svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.theme-chip:hover {
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
  background: color-mix(in srgb, var(--md-sys-color-primary) 6%, transparent);
}

.theme-chip.active {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* ── Context Dialog ── */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.dialog-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.dialog {
  background: var(--md-sys-color-surface);
  border-radius: 24px;
  width: min(560px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.22s cubic-bezier(.4,0,.2,1);
}

.dialog-backdrop.open .dialog {
  transform: translateY(0) scale(1);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
}

.dialog-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.dialog-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-desc {
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.5;
}

.context-restore-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: color-mix(in srgb, var(--md-sys-color-primary-container) 50%, transparent);
  border-radius: 10px;
  padding: 8px 12px;
}

.context-restore-bar[hidden] { display: none; }

.context-restore-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.83rem;
  color: var(--md-sys-color-on-primary-container);
  font-weight: 500;
}

.context-restore-hint svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

.context-restore-btn {
  border: none;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-radius: 50px;
  padding: 4px 14px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.context-restore-btn:hover { opacity: 0.85; }

.context-textarea {
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: 12px;
  font-family: inherit;
  font-size: 0.93rem;
  line-height: 1.6;
  resize: vertical;
  min-height: 130px;
  background: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: border-color 0.15s;
}

.context-textarea:focus {
  border-color: var(--md-sys-color-primary);
}

.context-textarea::placeholder {
  color: var(--md-sys-color-outline);
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 20px 20px;
}

.dialog-footer md-text-button {
  --md-text-button-container-height: 44px;
  min-width: 96px;
}

.dialog-footer md-filled-button {
  --md-filled-button-container-height: 44px;
  min-width: 96px;
}

/* ── Bottom Nav (mobile) ── */
.bottom-nav { display: none; }

/* ── Responsive ── */
@media (max-width: 780px) {
  :root { --nav-width: 0px; }
  .nav-rail { display: none; }
  .main-wrap { margin-left: 0; padding-bottom: 72px; }
  .page { padding: 20px 16px; }
  .text-panels { grid-template-columns: 1fr; }
  .history-text { grid-template-columns: 1fr; }
  .lang-bar { flex-wrap: wrap; }
  .theme-chips { flex-wrap: wrap; }
  .setting-row { flex-direction: column; align-items: flex-start; }
  .page-header { flex-direction: column; align-items: flex-start; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--nav-bg);
    border-top: 1px solid var(--md-sys-color-outline-variant);
    z-index: 100;
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 8px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 500;
    transition: color 0.15s;
    position: relative;
  }

  .bottom-nav-item svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
  }

  .bottom-nav-item.active { color: var(--md-sys-color-primary); }

  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 3px;
    background: var(--md-sys-color-primary);
    border-radius: 0 0 3px 3px;
  }
}
/* ── Image Page ── */
.image-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.image-upload-area {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--md-sys-color-outline-variant);
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
  overflow: hidden;
  padding: 0;
}

.image-upload-area:hover,
.image-upload-area.drag-over {
  border-color: var(--md-sys-color-primary);
  background: color-mix(in srgb, var(--md-sys-color-primary) 4%, var(--md-sys-color-surface));
}

.image-upload-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px;
  text-align: center;
}

.image-upload-inner svg {
  width: 48px;
  height: 48px;
  fill: var(--md-sys-color-outline);
  margin-bottom: 4px;
}

.image-upload-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.image-upload-hint {
  font-size: 0.83rem;
  color: var(--md-sys-color-on-surface-variant);
}

.image-pick-btn {
  margin-top: 8px;
  padding: 8px 20px;
  border: none;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-radius: 50px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.image-pick-btn:hover { opacity: 0.85; }

.image-preview-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 180px;
}

.image-preview-img {
  max-width: 100%;
  max-height: 320px;
  border-radius: 12px;
  object-fit: contain;
  display: block;
}

.image-remove-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--md-sys-color-surface);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: background 0.15s;
}

.image-remove-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.image-remove-btn:hover {
  background: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface);
}

.image-result-panel textarea {
  min-height: 180px;
}

/* ── Writing Page ── */
.writing-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.writing-result-content {
  flex: 1;
  padding: 14px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface);
  min-height: 220px;
  overflow-y: auto;
  word-break: break-word;
  white-space: pre-wrap;
}

.writing-result-content:empty::before {
  content: attr(data-placeholder);
  color: var(--md-sys-color-outline);
}

/* Diff highlighting */
.diff-added {
  color: #1a7a3a;
  text-decoration: underline;
  text-decoration-color: #1a7a3a;
  text-underline-offset: 2px;
}

:root[data-theme="dark"] .diff-added {
  color: #4fc878;
  text-decoration-color: #4fc878;
}

.diff-removed {
  color: #8a8a8a;
  text-decoration: line-through;
  text-decoration-color: #8a8a8a;
}

:root[data-theme="dark"] .diff-removed {
  color: #6b6b6b;
  text-decoration-color: #6b6b6b;
}

/* Writing mode toggle button */
.writing-mode-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border: 2px solid var(--md-sys-color-outline-variant);
  border-radius: 50px;
  background: transparent;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.writing-mode-toggle svg {
  fill: currentColor;
  flex-shrink: 0;
}

.writing-mode-toggle:hover {
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}

.writing-mode-toggle[data-active="true"] {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

@media (max-width: 780px) {
  .image-upload-inner { padding: 20px 16px; }
  .image-grid { gap: 12px; }
  .writing-grid { gap: 12px; }
}

/* ── Image mode chips ── */
.image-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.image-selector-row {
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.image-selector-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.image-selector-divider {
  width: 1px;
  background: var(--md-sys-color-outline-variant);
  align-self: stretch;
  margin: 0 16px;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .image-selector-row { flex-direction: column; gap: 12px; }
  .image-selector-divider { width: auto; height: 1px; margin: 0; }
}

.image-mode-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--md-sys-color-on-surface-variant);
}

.image-mode-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-mode-chip {
  padding: 7px 16px;
  border: 2px solid var(--md-sys-color-outline-variant);
  border-radius: 50px;
  background: transparent;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.image-mode-chip:hover {
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
  background: color-mix(in srgb, var(--md-sys-color-primary) 5%, transparent);
}

.image-mode-chip.active {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 600;
}

.image-mode-desc {
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.4;
  min-height: 1.2em;
}