* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  line-height: 1.5;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
}
header h1 {
  margin: 0;
  font-size: 18px;
}
#key-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
#key {
  padding: 4px 8px;
  background: #0d1117;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 4px;
  width: 160px;
}
button {
  padding: 4px 12px;
  background: #238636;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
button:hover {
  background: #2ea043;
}
#status {
  color: #8b949e;
}

main {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1100px;
  margin: 0 auto;
}
section h2 {
  font-size: 14px;
  color: #8b949e;
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.msg {
  padding: 12px;
  margin-bottom: 10px;
  background: #161b22;
  border-radius: 6px;
  border-left: 3px solid #30363d;
}
.msg.user {
  border-left-color: #58a6ff;
}
.msg.assistant {
  border-left-color: #f78166;
}
.meta {
  font-size: 11px;
  color: #8b949e;
  margin-bottom: 6px;
}
.zh {
  color: #c9d1d9;
}
.en {
  color: #58a6ff;
  margin-top: 4px;
  font-style: italic;
}
.raw {
  color: #8b949e;
  font-size: 13px;
}
.en.summary {
  font-style: normal;
  color: #7ee787;
}
details.raw {
  margin-top: 6px;
}
details.raw summary {
  cursor: pointer;
  color: #6e7681;
  font-size: 11px;
}
details.raw > *:not(summary) {
  margin-top: 4px;
}
.chips {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #21262d;
}
.chip.known {
  background: #1a3a2a;
  color: #7ee787;
}
.chip.conflict {
  background: #4a2a1a;
  color: #ffa657;
}

.word {
  display: block;
  padding: 8px 10px;
  background: #161b22;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 13px;
}
.word-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.word .w {
  color: #58a6ff;
}
.word .g {
  color: #c9d1d9;
  flex: 1;
  margin: 0 8px;
}
.word .count {
  color: #8b949e;
  font-size: 11px;
  min-width: 24px;
  text-align: right;
}
.word.known {
  opacity: 0.5;
}
.word .mark {
  padding: 2px 8px;
  font-size: 12px;
  background: #21262d;
  color: #8b949e;
  border: 1px solid #30363d;
}
.word .mark:hover {
  background: #238636;
  color: #fff;
}
.word .mark.done {
  background: #1a3a2a;
  color: #7ee787;
  border-color: #2ea043;
  cursor: default;
}
.word-detail {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #30363d;
  font-size: 12px;
}
.word-detail .meaning {
  margin-bottom: 6px;
  line-height: 1.5;
}
.word-detail .mg {
  color: #f0883e;
}
.word-detail .ex {
  color: #8b949e;
  display: block;
  font-size: 11px;
}

/* --- nav link (shared by table + gallery headers) --- */
nav a {
  color: #58a6ff;
  text-decoration: none;
  font-size: 13px;
  margin-left: 12px;
  white-space: nowrap;
}
nav a:hover {
  text-decoration: underline;
}

/* --- gallery view --- */
body.gallery {
  overflow: hidden;
}
body.gallery header {
  position: relative;
  z-index: 2;
}
#labels {
  position: fixed;
  top: 56px;
  left: 0;
  width: 100%;
  height: calc(100vh - 56px);
  pointer-events: none;
  z-index: 1;
}
#labels .label {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  color: #c9d1d9;
  font-size: 12px;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  background: rgba(13, 17, 23, 0.6);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
  transition:
    font-size 0.1s,
    color 0.1s;
}
#labels .label.known {
  color: #3fb950;
  opacity: 0.7;
}
#labels .label.hover {
  color: #fff;
  font-size: 15px;
  background: rgba(88, 166, 255, 0.25);
  z-index: 2;
}
#galaxy {
  display: block;
  position: fixed;
  top: 56px;
  left: 0;
  cursor: grab;
}
#hint {
  position: fixed;
  bottom: 12px;
  left: 16px;
  color: #6e7681;
  font-size: 12px;
  z-index: 2;
  pointer-events: none;
}
#detail {
  position: fixed;
  top: 70px;
  right: 16px;
  width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 16px;
  z-index: 3;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
#detail h3 {
  margin: 0 0 6px;
  color: #58a6ff;
  font-size: 16px;
}
#detail .g {
  color: #8b949e;
  font-size: 12px;
  margin-bottom: 10px;
}
#detail .meaning {
  margin-bottom: 8px;
  line-height: 1.5;
  font-size: 13px;
}
#detail .mg {
  color: #f0883e;
}
#detail .ex {
  color: #8b949e;
  display: block;
  font-size: 11px;
}
#detail .detail-loading {
  color: #6e7681;
  font-size: 12px;
}
#detail-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  color: #8b949e;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
}
#detail-close:hover {
  color: #fff;
}

@media (max-width: 700px) {
  main {
    grid-template-columns: 1fr;
  }
  #detail {
    width: calc(100vw - 32px);
    right: 16px;
    left: 16px;
  }
}
