:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --ink: #1c2530;
  --muted: #5f6875;
  --line: #d4dae3;
  --accent: #0d6d5f;
  --accent-soft: #d8f2ed;
  --danger: #c33d2e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top right, #e8f7f2 0, var(--bg) 40%);
}

.app-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.brand-mark {
  width: 1.35rem;
  height: 1.35rem;
  border: 1px solid #9bc7c0;
  border-radius: 6px;
  background: linear-gradient(145deg, var(--accent-soft), #eef7f4);
  display: grid;
  place-items: center;
  position: relative;
  color: var(--accent);
}

.brand-note {
  width: 1rem;
  height: 1rem;
  display: block;
}

.brand-text {
  font-family: "Avenir Next", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: #125e53;
}

.project-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.menu-bar {
  display: flex;
  gap: 0.75rem;
}

.github-fork-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.86rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid transparent;
}

.github-fork-link svg {
  width: 0.95rem;
  height: 0.95rem;
  flex: 0 0 auto;
}

.github-fork-link:hover {
  color: var(--ink);
  background: var(--accent-soft);
  border-color: #b9ddd6;
}

.menu {
  position: relative;
}

.menu > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  user-select: none;
}

.menu > summary:hover,
.menu[open] > summary {
  background: var(--accent-soft);
}

.menu-launcher {
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
}

.menu-launcher:hover {
  background: var(--accent-soft);
  border-color: transparent;
}

.menu > summary::-webkit-details-marker {
  display: none;
}

.menu-items {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 180px;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  display: grid;
  gap: 0.2rem;
}

.menu-items button,
.menu-items label {
  border: 0;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
}

.menu-items button:hover,
.menu-items label:hover {
  background: var(--accent-soft);
}

.menu-items label {
  display: grid;
  gap: 0.25rem;
}

.menu-items select {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: 1.6fr 0.9fr;
  gap: 0.75rem;
  padding: 0.75rem;
  height: calc(100vh - 64px);
}

.workspace.editor-bottom {
  grid-template-columns: 1.6fr 0.9fr;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.panel h2 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.segment-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0.35rem 0.6rem;
}

button:hover {
  border-color: var(--accent);
}

.segment-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}

.segment-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  background: #fcfdfd;
  cursor: pointer;
  line-height: 1.4;
  width: 100%;
  min-width: 0;
}

.segment-item:hover {
  border-color: var(--accent);
}

.segment-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  cursor: default;
}

.segment-content {
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}

.segment-edit-block {
  min-width: 0;
}

.segment-source {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.workspace.editor-right .segment-item.active .segment-content {
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  align-items: start;
}

.workspace.editor-bottom .segment-item.active .segment-content {
  grid-template-columns: 1fr;
}

.segment-edit-label {
  display: block;
  margin-bottom: 0.2rem;
  min-width: 0;
}

.segment-edit-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.segment-auto-translate-btn {
  white-space: nowrap;
}

.segment-translation-input {
  min-height: 120px;
  resize: vertical;
}

.segment-inline-glossary {
  margin-bottom: 0.3rem;
  min-width: 0;
}

.segment-inline-glossary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  min-height: 1.25rem;
  min-width: 0;
}

.segment-inline-glossary-text {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 0;
}

.segment-inline-glossary-text:hover {
  text-decoration: underline;
}

.segment-add-glossary-btn {
  padding: 0.12rem 0.42rem;
  font-size: 0.72rem;
  border-radius: 999px;
  flex: 0 0 auto;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  font: inherit;
}

textarea {
  min-height: 130px;
  resize: vertical;
}

.sidebar-note {
  color: var(--muted);
  margin: 0;
}

.glossary-list {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

#add-glossary-btn {
  margin-bottom: 0.5rem;
}

.glossary-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
}

.glossary-list strong {
  display: block;
}

.hidden {
  display: none;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  width: min(440px, calc(100vw - 2rem));
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

dialog form {
  display: grid;
  gap: 0.65rem;
  padding: 1rem;
}

dialog menu {
  display: flex;
  justify-content: end;
  gap: 0.5rem;
  margin: 0.3rem 0 0;
  padding: 0;
}

.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 24, 21, 0.24);
  z-index: 70;
}

.onboarding-popover {
  position: fixed;
  width: min(360px, calc(100vw - 2rem));
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.16);
  padding: 0.8rem;
  z-index: 80;
}

.onboarding-header {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.onboarding-step {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.onboarding-title {
  margin: 0.35rem 0 0.3rem;
  font-size: 1rem;
}

.onboarding-body {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
}

.onboarding-actions {
  margin-top: 0.7rem;
  display: flex;
  justify-content: space-between;
  gap: 0.45rem;
}

.onboarding-highlight {
  position: relative;
  z-index: 75;
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 8px;
}

@media (max-width: 980px) {
  .workspace,
  .workspace.editor-bottom {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    height: auto;
  }

  .app-header {
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .menu-bar {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .project-meta {
    width: 100%;
    margin-left: 0;
  }

  .github-fork-link {
    order: 4;
  }

  .workspace.editor-right .segment-item.active .segment-content {
    grid-template-columns: 1fr;
  }

  .glossary-panel {
    display: none;
  }
}

@media (max-width: 400px) {
  .app-header {
    padding: 0.6rem 0.6rem;
  }

  .workspace {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .panel {
    padding: 0.55rem;
  }

  .brand-text {
    font-size: 0.95rem;
    letter-spacing: 0.01em;
  }

  .github-fork-link {
    font-size: 0.78rem;
    padding: 0.2rem 0.35rem;
    gap: 0.25rem;
  }

  .menu > summary,
  .menu-launcher {
    padding: 0.26rem 0.44rem;
    font-size: 0.86rem;
  }

  .segment-item {
    padding: 0.42rem;
  }

  .segment-add-glossary-btn,
  .segment-auto-translate-btn {
    white-space: normal;
  }

  .segment-edit-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .segment-auto-translate-btn {
    width: 100%;
  }
}

@media (max-width: 320px) {
  .brand-text {
    display: none;
  }

  .segment-inline-glossary-text {
    font-size: 0.72rem;
  }

  #fork-github-label {
    display: none;
  }

  button {
    padding: 0.28rem 0.45rem;
    font-size: 0.82rem;
  }
}
