:root {
  --brand: #f8ac10;
  --sector: #7c3aed;
  --bg: #050505;
  --panel: #111111;
  --panel-2: #191919;
  --ink: #fff8e8;
  --muted: #b9b0a1;
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --reader-size: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 8%, rgba(248, 172, 16, 0.2), transparent 24rem),
    radial-gradient(circle at 84% 18%, rgba(124, 58, 237, 0.24), transparent 28rem),
    var(--bg);
  font-family: "Special Elite", monospace;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(5, 5, 5, 0.88);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand-lockup {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 2px solid var(--brand);
  color: var(--brand);
  font-size: 24px;
  transform: rotate(-2deg);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.08;
}

.control-group,
.panel,
.glossary-editor {
  border: 1px solid var(--line);
  background: rgba(17, 17, 17, 0.84);
}

.control-group {
  display: grid;
  gap: 10px;
  padding: 16px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #080808;
  color: var(--ink);
  padding: 12px;
  outline: none;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(248, 172, 16, 0.16);
}

.panel {
  padding: 16px;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 15px;
}

.panel-header span {
  color: var(--sector);
  font-weight: 800;
}

.text-list {
  display: grid;
  gap: 10px;
}

.text-card {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.text-card:hover,
.text-card.active {
  border-color: var(--brand);
}

.text-card-main {
  min-width: 0;
  min-height: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 6px 4px;
  text-align: left;
}

.text-card-main:hover {
  filter: none;
}

.text-card-main strong {
  display: block;
  margin-bottom: 5px;
  overflow-wrap: anywhere;
}

.text-card-main span {
  color: var(--muted);
  font-size: 12px;
}

.delete-text {
  min-height: 34px;
  border: 1px solid rgba(124, 58, 237, 0.5);
  background: rgba(124, 58, 237, 0.16);
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
}

.delete-text:hover {
  background: var(--sector);
  filter: none;
}

.text-form,
.glossary-form {
  display: grid;
  gap: 10px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #110b00;
  font-weight: 900;
}

button:hover {
  filter: brightness(1.05);
}

.reader {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 22px;
  padding: 30px clamp(20px, 5vw, 64px);
}

.reader-top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 22px;
}

.reader-top h2 {
  margin-bottom: 0;
  max-width: 780px;
  font-size: clamp(32px, 5vw, 68px);
  line-height: 0.98;
  color: var(--ink);
}

.reader-actions {
  display: flex;
  gap: 8px;
}

.reader-actions button {
  width: 48px;
  min-height: 40px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.reading-text {
  max-width: 920px;
  align-self: start;
  font-size: var(--reader-size);
  line-height: 1.82;
  color: #fff6df;
}

.reading-text p {
  margin: 0 0 24px;
}

.word {
  border: 0;
  border-bottom: 2px solid rgba(248, 172, 16, 0.34);
  border-radius: 0;
  min-height: auto;
  padding: 0 1px 2px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
}

.word:hover,
.word:focus {
  color: var(--brand);
  outline: none;
}

.word[data-known="false"] {
  border-bottom-color: rgba(124, 58, 237, 0.55);
}

.glossary-editor {
  padding: 18px;
}

.glossary-editor h3 {
  margin-bottom: 14px;
  font-size: 18px;
}

.glossary-form {
  grid-template-columns: 1fr 1fr 150px minmax(220px, 1.2fr) auto;
}

.word-popup {
  position: fixed;
  z-index: 20;
  width: min(330px, calc(100vw - 28px));
  border: 1px solid rgba(248, 172, 16, 0.48);
  border-radius: 8px;
  background: rgba(8, 8, 8, 0.97);
  box-shadow: var(--shadow);
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.word-popup.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.popup-tag-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.part-tag,
.direction-tag {
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.part-tag {
  background: var(--sector);
  color: white;
}

.direction-tag {
  background: rgba(248, 172, 16, 0.16);
  color: var(--brand);
}

.word-popup h3 {
  margin-bottom: 8px;
  font-size: 28px;
}

.translation {
  margin-bottom: 8px;
  color: var(--brand);
  font-size: 20px;
  font-weight: 900;
}

.explanation {
  color: var(--muted);
  line-height: 1.5;
}

#popupAdd {
  width: 100%;
  margin-top: 4px;
  background: var(--sector);
  color: white;
}

/* ---- voice selector ---- */
#voiceSelect {
  min-height: 40px;
  max-width: 180px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #080808;
  color: var(--muted);
  font-size: 12px;
  padding: 0 8px;
}

#voiceSelect:focus {
  border-color: var(--brand);
  outline: none;
}

/* ---- speech button ---- */
#speechBtn {
  min-width: 80px;
  min-height: 40px;
  background: transparent;
  border: 1px solid var(--brand);
  color: var(--brand);
  font-size: 13px;
  letter-spacing: 0.04em;
}

#speechBtn:hover {
  background: rgba(248, 172, 16, 0.12);
  filter: none;
}

/* ---- translate button ---- */
#translateBtn {
  min-width: 110px;
  min-height: 40px;
  background: transparent;
  border: 1px solid var(--sector);
  color: #c4a8ff;
  font-size: 13px;
  letter-spacing: 0.04em;
}

#translateBtn:hover {
  background: rgba(124, 58, 237, 0.14);
  filter: none;
}

#translateBtn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.translated-paragraph {
  color: #c4a8ff;
  font-style: italic;
}

/* ---- custom text edit ---- */
.text-edit-form {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding: 4px 0;
}

.edit-title-input,
.edit-body-input {
  width: 100%;
}

.edit-actions {
  display: flex;
  gap: 8px;
}

.edit-actions .save-edit-text {
  flex: 1;
  background: var(--brand);
  color: #110b00;
}

.cancel-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.cancel-btn:hover {
  background: rgba(255,255,255,0.06);
  filter: none;
}

.edit-text {
  min-height: 34px;
  border: 1px solid rgba(248, 172, 16, 0.5);
  background: rgba(248, 172, 16, 0.12);
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
}

.edit-text:hover {
  background: var(--brand);
  color: #110b00;
  filter: none;
}

/* ---- custom glossary list ---- */
.custom-glossary-list {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  display: grid;
  gap: 8px;
}

.no-glossary-entries {
  color: var(--muted);
  font-size: 13px;
}

.glossary-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.glossary-row-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.glossary-row-info strong {
  color: var(--ink);
  font-size: 14px;
}

.glossary-arrow {
  color: var(--brand);
  font-size: 13px;
}

.glossary-arrow::before {
  content: "→ ";
  opacity: 0.5;
}

.glossary-part {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.glossary-edit-btn {
  min-height: 30px;
  border: 1px solid rgba(248, 172, 16, 0.5);
  background: rgba(248, 172, 16, 0.12);
  color: var(--ink);
  padding: 0 10px;
  font-size: 11px;
}

.glossary-edit-btn:hover {
  background: var(--brand);
  color: #110b00;
  filter: none;
}

.glossary-delete-btn {
  min-height: 30px;
  border: 1px solid rgba(124, 58, 237, 0.5);
  background: rgba(124, 58, 237, 0.16);
  color: var(--ink);
  padding: 0 10px;
  font-size: 11px;
}

.glossary-delete-btn:hover {
  background: var(--sector);
  filter: none;
}
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .glossary-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  .sidebar,
  .reader {
    padding: 18px;
  }

  .reader-top {
    align-items: start;
    flex-direction: column;
  }

  .glossary-form {
    grid-template-columns: 1fr;
  }
}
