:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #ffffff;
  --text: #111111;
  --muted: #888888;
  --line: #e0e0e0;
  --accent: #111111;
  --accent-text: #ffffff;
  --danger: #888888;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

:root.dark {
  color-scheme: dark;
  --bg: #111111;
  --surface: #1a1a1a;
  --text: #f2f2f2;
  --muted: #666666;
  --line: #2a2a2a;
  --accent: #f2f2f2;
  --accent-text: #111111;
  --danger: #666666;
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button, input { font: inherit; cursor: pointer; }
input { cursor: text; }

.app {
  width: min(640px, 100%);
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(32px + env(safe-area-inset-bottom));
  display: grid;
  gap: 1px;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1px;
}

.eyebrow { display: none; }

h1 {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

h2 {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Panels ── */
.search-panel,
.quick-section,
.browser-section {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 20px;
}

.search-panel { margin-top: 1px; }

.panel-heading { margin-bottom: 20px; }
.panel-heading p { display: none; }

.search-form { display: grid; gap: 10px; }

label {
  display: grid;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  padding: 0 12px;
  outline: none;
  transition: border-color 120ms;
}

input:focus { border-color: var(--text); }

.primary-button {
  height: 44px;
  padding: 0 20px;
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  border-radius: 0;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.translation-box {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  gap: 4px;
}

.translation-box span {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.translation-box strong {
  font-size: 1rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* ── Sections ── */
.quick-section { margin-top: 1px; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title button {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── Chips ── */
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 500;
  transition: background 100ms, border-color 100ms, color 100ms;
}

.chip.active,
.chip:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* ── Tool grid ── */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  margin-top: 14px;
  background: var(--line);
  border: 1px solid var(--line);
}

.tool-card {
  background: var(--surface);
  border: none;
  color: var(--text);
  padding: 14px;
  text-align: left;
  transition: background 100ms;
}

.tool-card:hover { background: var(--bg); }

.tool-card span,
.item span {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.tool-card strong,
.item strong {
  display: block;
  margin-top: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* ── Browser ── */
.browser-section {
  display: none;
  margin-top: 1px;
  overflow: hidden;
  padding: 0;
}

.browser-section.active { display: block; }

.browser-section.expanded {
  position: fixed;
  inset: 0;
  z-index: 10;
  margin: 0;
  border: none;
}

.browser-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.browser-toolbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.browser-actions { display: flex; gap: 6px; }

.browser-actions button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.frame-wrap {
  position: relative;
  height: min(72vh, 760px);
  min-height: 500px;
  background: var(--surface);
}

.browser-section.expanded .frame-wrap {
  height: calc(100vh - 65px);
}

iframe { width: 100%; height: 100%; border: 0; }

.frame-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
  font-size: 0.85rem;
}

.frame-hint.hidden { display: none; }
.frame-hint strong { color: var(--text); font-weight: 500; }

/* ── History ── */
.history-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin-top: 1px;
}

.history-layout .quick-section { margin-top: 0; }

.list { display: grid; gap: 1px; background: var(--line); }

.item {
  width: 100%;
  border: none;
  background: var(--surface);
  color: var(--text);
  padding: 12px;
  text-align: left;
  transition: background 100ms;
}

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

.empty-state {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.empty-state.hidden { display: none; }

/* ── Toast ── */
.toast {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 99;
  max-width: min(320px, calc(100vw - 32px));
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.85rem;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.visible { opacity: 1; transform: translateY(0); }

/* ── Mobile ── */
@media (max-width: 480px) {
  .app { padding-inline: 16px; gap: 1px; }

  .search-row { grid-template-columns: 1fr; }
  .field-grid { grid-template-columns: 1fr; }

  .primary-button { width: 100%; }

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

  .history-layout { grid-template-columns: 1fr; }

  .frame-wrap { height: 65vh; min-height: 420px; }
}
