:root {
  --paper: #f2f0e8;
  --white: #fffef9;
  --ink: #111313;
  --muted: #72756f;
  --line: rgba(17, 19, 19, 0.18);
  --cyan: #00e5c0;
  --panel-width: min(430px, 92vw);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #d9d7cf;
  font-family: "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.reader-bar {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 62px;
  padding: 0 18px;
  color: var(--paper);
  background: var(--ink);
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.reader-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  width: fit-content;
  color: inherit;
  text-decoration: none;
  font-size: 13px;
  letter-spacing: .1em;
}

.reader-brand span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--ink);
  background: var(--cyan);
  font: 800 11px/1 Consolas, monospace;
}

.reader-hint {
  color: #aeb2ad;
  font-size: 12px;
}

.reader-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 12px;
}

.reader-actions a {
  color: #bfc2bd;
  font-size: 12px;
  text-decoration: none;
}

.reader-actions button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--cyan);
  color: var(--ink);
  background: var(--cyan);
  cursor: pointer;
  font-weight: 700;
}

.reader-actions i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 4px rgba(17, 19, 19, .12);
}

.reader-stage {
  position: relative;
  height: calc(100% - 62px);
}

#library-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
  transition: width .3s ease;
}

body.panel-open #library-frame { width: calc(100% - var(--panel-width)); }

.companion-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  width: var(--panel-width);
  padding: 22px;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  background: var(--paper);
  border-left: 1px solid var(--ink);
  box-shadow: -18px 0 45px rgba(17, 19, 19, .16);
  transform: translateX(105%);
  transition: transform .3s ease;
}

body.panel-open .companion-panel { transform: translateX(0); }

.companion-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.companion-head small {
  color: #08796b;
  font: 600 9px/1 Consolas, monospace;
  letter-spacing: .16em;
}

.companion-head h1 {
  margin: 8px 0 0;
  font-family: "Songti SC", STSong, serif;
  font-size: 31px;
  line-height: 1;
}

.companion-head button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-size: 23px;
  line-height: 1;
}

.selection-card {
  position: relative;
  padding: 15px;
  background: var(--white);
  border: 1px solid var(--line);
}

.selection-card label,
#companion-form label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
}

#selected-text {
  display: block;
  width: 100%;
  min-height: 112px;
  padding: 0 0 22px;
  resize: vertical;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 13px;
  line-height: 1.7;
}

#selection-count {
  position: absolute;
  right: 14px;
  bottom: 10px;
  color: var(--muted);
  font: 10px/1 Consolas, monospace;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.quick-actions button {
  padding: 10px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.quick-actions button:hover,
.quick-actions button.is-active {
  background: var(--cyan);
}

.answer-card {
  min-height: 170px;
  padding: 18px;
  color: #e9ece6;
  background: var(--ink);
  border-left: 4px solid var(--cyan);
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.75;
}

.answer-card .empty-answer { margin: 0; color: #9ea19c; }
.answer-card[data-state="loading"] { color: var(--cyan); }
.answer-card[data-state="error"] { color: #ffb9a8; }

#companion-form { margin-top: auto; }

.question-row { display: grid; grid-template-columns: 1fr auto; }

.question-row input {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--ink);
  border-right: 0;
  background: var(--white);
  outline: none;
}

.question-row button {
  padding: 0 17px;
  border: 1px solid var(--ink);
  color: var(--paper);
  background: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

#companion-form > p { margin: 9px 0 0; color: var(--muted); font-size: 10px; }

@media (max-width: 760px) {
  .reader-bar { grid-template-columns: 1fr auto; height: 58px; padding: 0 10px; }
  .reader-hint, .reader-actions a, .reader-brand strong { display: none; }
  .reader-stage { height: calc(100% - 58px); }
  body.panel-open #library-frame { width: 100%; }
  .companion-panel { width: 100%; border-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #library-frame, .companion-panel { transition: none; }
}
