:root {
  color-scheme: light;
  --bg: #ececec;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-solid: #ffffff;
  --line: rgba(60, 60, 67, 0.12);
  --text: #111111;
  --muted: #5d5d63;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.08);
  --inset: rgba(255, 255, 255, 0.65);
  --tag: rgba(17, 17, 17, 0.06);
  --accent: #111111;
  --row-active: rgba(17, 17, 17, 0.06);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f10;
  --panel: rgba(28, 28, 30, 0.82);
  --panel-solid: #171718;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f5f7;
  --muted: #b2b2b8;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --inset: rgba(255, 255, 255, 0.04);
  --tag: rgba(255, 255, 255, 0.08);
  --accent: #ffffff;
  --row-active: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.5), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 28%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

.workspace {
  padding: 18px;
  height: 100vh;
}

.columns {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: clamp(260px, calc((100vw - 72px) / 3), 380px);
  gap: 18px;
  align-items: stretch;
  overflow-x: auto;
  min-height: 100%;
  max-height: 100%;
}

.window {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 14px;
  min-height: 0;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

@media (max-width: 820px) {
  html,
  body {
    overflow: auto;
  }

  .workspace {
    padding: 14px;
    height: auto;
    min-height: 100vh;
  }

  .columns {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow: visible;
  }

  .window {
    max-height: none;
    overflow: visible;
    border-radius: 22px;
    padding: 14px;
  }

  .window-bar {
    margin-bottom: 12px;
  }
}

.window-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.traffic-lights {
  display: flex;
  gap: 6px;
}

.light {
  padding: 0;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
  border: 0;
}

.light.red { background: #ff5f57; }
.light.yellow { background: #febc2e; }
.light.green { background: #28c840; }

.window-title {
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
}

.window-spacer {
  width: 56px;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-label,
.advanced-title {
  font-size: 0.92rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 46px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--text);
  padding: 0 14px;
  font-size: 1rem;
  outline: none;
  box-shadow: inset 0 1px 0 var(--inset);
}

button {
  border: 0;
  border-radius: 16px;
  min-height: 42px;
  padding: 0 14px;
  font: inherit;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.secondary-button,
.toolbar-button {
  background: var(--tag);
  color: var(--text);
  border: 1px solid var(--line);
}


.advanced-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  background: var(--tag);
}

.search-launch {
  margin-top: 12px;
}

.history-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  background: var(--tag);
}

.history-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  color: var(--text);
}

.history-delete {
  color: #ff5f57;
  font-size: 0.82rem;
}

.history-empty {
  color: var(--muted);
  line-height: 1.6;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.status {
  margin: 14px 2px 2px;
  color: var(--muted);
  line-height: 1.6;
}

.idiom-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tail-summary {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.tail-summary-title {
  font-size: 0.86rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.tail-summary-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 8px;
}

.tail-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(to right, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), var(--line) calc(50% - 0.5px), var(--line) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    var(--panel-solid);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.tail-char.danger {
  border-color: #ff5f57;
  box-shadow: inset 0 0 0 1px rgba(255, 95, 87, 0.18);
}

.tail-char.active {
  background:
    linear-gradient(to right, transparent calc(50% - 0.5px), rgba(255, 255, 255, 0.18) calc(50% - 0.5px), rgba(255, 255, 255, 0.18) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), rgba(255, 255, 255, 0.18) calc(50% - 0.5px), rgba(255, 255, 255, 0.18) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    var(--accent);
  color: var(--bg);
}

.idiom-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--inset);
  scroll-margin-top: 92px;
}

.idiom-row.active {
  background: var(--row-active);
  border-color: rgba(128, 128, 128, 0.3);
}


.idiom-word {
  font-weight: 700;
  text-align: left;
}

.idiom-tag {
  flex-shrink: 0;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--tag);
  color: var(--muted);
  font-size: 0.82rem;
}

.idiom-detail,
.empty-state,
.loading-state {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  line-height: 1.7;
  color: var(--muted);
}

.idiom-detail p {
  margin: 0;
}

.idiom-detail p + p {
  margin-top: 8px;
}

.detail-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.86rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 12, 0.28);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: 16px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 18px;
  overflow: auto;
}

.search-modal-panel {
  min-height: calc(100vh - 32px);
}

.search-input-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--panel-solid) 72%, transparent);
  box-shadow: inset 0 1px 0 var(--inset);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  background: var(--tag);
  border: 1px solid var(--line);
  color: var(--text);
}

.modal-input {
  margin: 0;
}

.search-clear {
  min-width: 42px;
  background: color-mix(in srgb, var(--tag) 70%, transparent);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 1.1rem;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-result {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--text);
}

.search-result span,
.search-empty,
.detail-content {
  color: var(--muted);
  line-height: 1.7;
}

.detail-content p {
  margin: 0;
}

.detail-content p + p {
  margin-top: 8px;
}

@media (max-width: 900px) {
  .columns {
    grid-auto-columns: minmax(84vw, 1fr);
  }
}
