:root {
  --bg: #f8f3e8;
  --ink: #1e2a2f;
  --muted: #5e6b70;
  --surface: #fffdf8;
  --line: #dfd8c8;
  --accent: #0b7a6b;
  --accent-soft: #d6efe9;
  --alert: #c24e29;
  --alert-soft: #ffe9de;
  --shadow: 0 20px 40px rgba(32, 38, 44, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #fff8e8 0%, var(--bg) 45%, #efe7d7 100%);
  font-family: "Manrope", "Segoe UI", sans-serif;
}

.bg-shape {
  position: fixed;
  z-index: 0;
  width: 34rem;
  height: 34rem;
  pointer-events: none;
  filter: blur(48px);
  opacity: 0.36;
}

.bg-shape-a {
  top: -12rem;
  right: -8rem;
  background: #b4dfcf;
  animation: driftA 16s ease-in-out infinite;
}

.bg-shape-b {
  bottom: -15rem;
  left: -8rem;
  background: #efd8b2;
  animation: driftB 20s ease-in-out infinite;
}

.app {
  position: relative;
  z-index: 1;
  width: calc(100vw - 2rem);
  max-width: none;
  margin: 1.4rem auto 2.4rem;
  display: grid;
  gap: 1rem;
}

.hero {
  background: linear-gradient(135deg, #fffaf0, #f4ead4);
  border: 1px solid #d9d0bc;
  border-radius: 1.2rem;
  padding: 0.5rem 0.9rem;
  box-shadow: var(--shadow);
  animation: riseIn 420ms ease-out both;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
}

.hero h1 {
  margin: 0;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: clamp(1.6rem, 2.2vw, 2rem);
  flex: 0 0 auto;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 1.03rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar,
.cards,
.footer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.48rem;
  padding: 0.56rem 0.64rem;
  overflow-x: auto;
  white-space: nowrap;
  animation: riseIn 520ms ease-out both;
}

.toolbar-main {
  background: linear-gradient(135deg, #fffaf0, #f4ead4);
  border-color: #d9d0bc;
  padding: 0.5rem 0.75rem;
}

.toolbar-main h1 {
  margin: 0 0.35rem 0 0;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: clamp(1.5rem, 2vw, 1.9rem);
  line-height: 1.1;
  flex: 0 0 auto;
  white-space: nowrap;
}

.stats-inline {
  display: flex;
  gap: 0.35rem;
  flex: 0 0 auto;
}

.stats-inline article {
  min-width: 5.6rem;
  background: #f5f1e7;
  border: 1px solid var(--line);
  border-radius: 0.62rem;
  padding: 0.22rem 0.4rem;
}

.stats-inline span {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.1;
}

.stats-inline small {
  color: var(--muted);
  font-size: 0.68rem;
}

.group {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  min-width: 0;
  flex: 0 0 auto;
}

.group label {
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

select,
input[type="text"],
textarea,
button {
  font: inherit;
}

select,
input[type="text"],
textarea {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.56rem 0.62rem;
  background: #fffefb;
  color: var(--ink);
}

textarea {
  width: 100%;
  min-width: 100%;
  max-width: 100%;
  display: block;
  min-height: 6.1rem;
  resize: vertical !important;
  line-height: 1.5;
}

textarea:focus,
select:focus,
input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.buttons {
  display: flex;
  gap: 0.35rem;
  white-space: nowrap;
}

button,
.import-label {
  border: 1px solid transparent;
  border-radius: 0.66rem;
  padding: 0.56rem 0.68rem;
  font-weight: 700;
  background: #102f3c;
  color: #f8fbfd;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:hover,
.import-label:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

button:active,
.import-label:active {
  transform: translateY(0);
}

#btn-next-pending,
#btn-export {
  background: #0f5e63;
}

#btn-reset {
  background: #7c4331;
}

.cards {
  padding: 0.8rem;
  display: grid;
  gap: 0.7rem;
}

.card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 0.8rem;
  background: linear-gradient(180deg, #fffefb, #f9f4ea);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.card-head h2 {
  margin: 0 0 0.2rem;
  font-family: "Fraunces", "Times New Roman", serif;
  font-size: 1.16rem;
}

.card-head p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.verse {
  margin: 0;
  line-height: 1.62;
  font-size: 2.12rem;
}

.verse-original {
  font-family: "Fraunces", "Times New Roman", serif;
}

#edited-input {
  width: 100% !important;
  min-width: 100% !important;
  max-width: 100% !important;
  font-size: 2.12rem;
  line-height: 1.35;
  height: calc(4 * 1.35em + 1.05rem);
  min-height: calc(4 * 1.35em + 1.05rem);
  overflow-y: auto;
  position: relative;
  z-index: 2;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  border: 1px solid transparent;
}

#edited-input::selection {
  background: rgba(255, 229, 138, 0.52);
  color: transparent;
}

#edited-input:focus {
  outline: none;
  border-color: transparent;
}

.edited-input-wrap {
  position: relative;
}

#edited-highlights {
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.56rem 0.62rem;
  background: #fffefb;
  color: var(--ink);
  font-size: 2.12rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  pointer-events: none;
  height: calc(4 * 1.35em + 1.05rem);
  min-height: calc(4 * 1.35em + 1.05rem);
  scrollbar-width: none;
}

#edited-highlights::-webkit-scrollbar {
  display: none;
}

.edited-input-wrap:focus-within #edited-highlights {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

#edited-card.card-saved {
  background: linear-gradient(180deg, #fffde7, #fff7c8);
  border-color: #e7d46e;
  box-shadow: inset 0 0 0 1px rgba(231, 212, 110, 0.45);
}

#edited-card.card-saved .card-head h2,
#edited-card.card-saved #status-label {
  color: #8a6d1f;
}

.inline-actions {
  margin-top: 0.55rem;
  display: flex;
  gap: 0.45rem;
}

.decision-wrap {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.decision-wrap label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

#decision-note {
  flex: 1 1 auto;
  font-size: 0.98rem;
  line-height: 1.2;
  min-height: 2.15rem;
  padding: 0.4rem 0.52rem;
}

.tm-manual {
  margin-top: 0.5rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  overflow-x: visible;
  white-space: normal;
}

.tm-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

.tm-compact-line {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.tm-compact-line input[type="text"] {
  min-width: 9rem;
  max-width: none;
  flex: 1 1 12rem;
  font-size: 0.86rem;
  padding: 0.38rem 0.48rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #fffefb;
}

.tm-compact-line #tm-rationale {
  flex: 1.2 1 14rem;
}

.tm-checkbox {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
  margin-left: 0.1rem;
}

.memory-apply-info {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: #0f5e63;
  min-height: 1.1rem;
}

.preview-wrap {
  margin-top: 0.7rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.6rem;
}

.preview-wrap h3 {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

mark.archaic {
  background: var(--alert-soft);
  border: 1px solid #efbdab;
  color: var(--alert);
  border-radius: 0.35rem;
  padding: 0.02rem 0.2rem;
}

.panel {
  background: #f6fbf9;
  border: 1px solid #d7e6e2;
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: 0.8rem;
}

.panel-head h2 {
  margin: 0;
  font-family: "Fraunces", "Times New Roman", serif;
}

.panel-head p {
  margin: 0.15rem 0 0.6rem;
  color: var(--muted);
}

#archaic-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.4rem;
}

#archaic-list li {
  border: 1px solid #c6d8d3;
  background: #ffffff;
  border-radius: 0.6rem;
  padding: 0.38rem 0.52rem;
}

#archaic-list li small {
  color: var(--muted);
  display: block;
}

.rae-link {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #0f5e63;
  text-decoration: none;
}

.rae-link:hover {
  text-decoration: underline;
}

.tm-actions {
  margin-top: 0.3rem;
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.tm-btn {
  border: 1px solid #9ebfba;
  border-radius: 0.45rem;
  padding: 0.22rem 0.42rem;
  font-size: 0.73rem;
  font-weight: 700;
  background: #eef8f5;
  color: #0f5e63;
  cursor: pointer;
}

.tm-btn:hover {
  background: #dff1ed;
}

.footer {
  padding: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

.footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

#import-file {
  display: none;
}

#autosave-label {
  color: var(--muted);
}

.grow {
  min-width: 0;
  flex: 1 1 16rem;
}

.group.grow input[type="text"] {
  width: 100%;
}

#chapter-select {
  width: 5.5rem;
}

#verse-select {
  width: 5.5rem;
}

.hotkey-hint {
  margin-left: 0.15rem;
  font-size: 0.72rem;
  color: var(--muted);
  flex: 0 0 auto;
}

.reveal {
  animation: riseIn 650ms ease-out both;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes driftA {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(-2rem, 2rem);
  }
}

@keyframes driftB {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(1.5rem, -2rem);
  }
}

@media (max-width: 900px) {
  .footer {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .app {
    width: calc(100vw - 1rem);
    margin: 0.7rem auto 1.2rem;
    gap: 0.7rem;
  }
  .toolbar-main h1 {
    font-size: 1.35rem;
  }
  .decision-wrap {
    flex-direction: column;
    align-items: stretch;
  }
  .tm-manual {
    flex-wrap: wrap;
    white-space: normal;
  }
  .tm-compact-line {
    flex-wrap: wrap;
  }
}
