/* ─── Ledger Panel ─── */
.ledger-panel,
.arg-modal,
.entry-modal {
  position: fixed;
  inset: 0;
}

.ledger-panel {
  z-index: 60;
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}

.ledger-shell {
  pointer-events: auto;
  width: min(460px, 100%);
  height: 100%;
  padding: 1rem;
  background: linear-gradient(180deg, rgba(7, 7, 15, 0.99), rgba(11, 11, 20, 0.99));
  border-left: 1px solid rgba(91, 196, 232, 0.14);
  box-shadow: -28px 0 70px rgba(0, 0, 0, 0.44);
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  gap: 1rem;
}

.ledger-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.ledger-kicker,
.arg-kicker,
.entry-kicker,
.entry-fragment-label {
  margin: 0;
  color: var(--ice);
  font-family: var(--font-heading);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.ledger-header h2 {
  margin: 0.35rem 0 0;
  font-size: 1.05rem;
  font-family: var(--font-display);
  font-weight: 400;
}

.ledger-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 1.5rem;
  transition: background 0.2s, border-color 0.2s;
}

.ledger-close:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.ledger-feed {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 0.2rem;
}

.ledger-message {
  padding: 0.95rem 1rem;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  animation: messageSlide 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.ledger-message.system {
  border-color: rgba(91, 196, 232, 0.14);
}

.ledger-message.user {
  background: rgba(232, 137, 60, 0.07);
  border-color: rgba(232, 137, 60, 0.14);
}

.ledger-message p {
  margin: 0;
  color: rgba(232, 228, 220, 0.84);
}

/* Typing indicator */
.ledger-typing {
  border-color: rgba(91, 196, 232, 0.1) !important;
  background: rgba(91, 196, 232, 0.03) !important;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 0.2rem 0;
}

.typing-dots span {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(91, 196, 232, 0.5);
  animation: typingBounce 1.3s ease infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.ledger-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.ledger-quick-actions button,
.ledger-form button,
.arg-btn {
  border-radius: 999px;
  border: 1px solid rgba(91, 196, 232, 0.24);
  background: rgba(91, 196, 232, 0.07);
  color: var(--crystal);
  min-height: 40px;
  padding: 0.7rem 0.95rem;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  transition: all 0.2s ease;
}

.ledger-quick-actions button:hover,
.ledger-form button:hover,
.arg-btn:hover {
  border-color: rgba(91, 196, 232, 0.5);
  background: rgba(91, 196, 232, 0.14);
  color: #fff;
  transform: translateY(-1px);
}

.ledger-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
}

.ledger-form input {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  padding: 0.82rem 1rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.ledger-form input:focus {
  border-color: rgba(91, 196, 232, 0.4);
}

.ledger-note,
.arg-note,
.arg-status,
.entry-instruction {
  margin: 0;
  color: var(--muted);
}

/* ─── ARG Modals ─── */
.arg-modal,
.entry-modal {
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(6, 6, 14, 0.92);
  backdrop-filter: blur(16px);
}

.arg-panel,
.entry-panel {
  width: min(760px, 100%);
  padding: 2.2rem;
  border-radius: 28px;
  border: 1px solid rgba(91, 196, 232, 0.16);
  background:
    radial-gradient(circle at top center, rgba(91, 196, 232, 0.08), transparent 42%),
    linear-gradient(180deg, rgba(14, 14, 28, 0.99), rgba(6, 6, 14, 0.99));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.56), 0 0 0 1px rgba(91, 196, 232, 0.06) inset;
  animation: modalEnter 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes modalEnter {
  from { opacity: 0; transform: translateY(30px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.arg-title {
  margin: 0.55rem 0 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  line-height: 1.15;
}

.arg-text,
.entry-body,
.entry-fragment-text {
  color: rgba(232, 228, 220, 0.78);
}

.arg-fragment,
.entry-fragment-box {
  margin: 1.2rem 0;
  padding: 1.1rem 1.2rem;
  border-radius: 16px;
  border-left: 2px solid rgba(91, 196, 232, 0.5);
  background: rgba(91, 196, 232, 0.04);
  font-style: italic;
}

.arg-code {
  display: inline-flex;
  margin: 0.35rem 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(212, 169, 64, 0.25);
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  background: rgba(212, 169, 64, 0.05);
}

.arg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 0.8rem 0 1rem;
}

.arg-status {
  min-height: 1.3rem;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ice);
}

/* ─── Entry Two Modal ─── */
.entry-panel {
  width: min(560px, 100%);
  text-align: center;
  position: relative;
  overflow: hidden;
}

/* Scan line effect */
.entry-panel::before {
  content: '';
  position: absolute;
  top: -100%;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(91, 196, 232, 0.4), transparent);
  animation: scanLine 3s linear infinite;
  pointer-events: none;
}

@keyframes scanLine {
  from { top: -2px; }
  to { top: 100%; }
}

.entry-body {
  line-height: 1.95;
  font-style: italic;
}

.entry-fragment-label {
  color: rgba(212, 169, 64, 0.72);
}

.entry-fragment-text {
  margin: 0.45rem 0 0;
  font-style: italic;
}

.entry-instruction strong {
  color: rgba(91, 196, 232, 0.88);
}

.entry-instruction span {
  color: rgba(212, 169, 64, 0.92);
  font-family: var(--font-heading);
  letter-spacing: 0.14em;
}

/* ─── TRACE-Ω Terminal ─── */
.trace-terminal {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: rgba(0, 4, 0, 0.88);
  backdrop-filter: blur(12px);
  animation: terminalFadeIn 0.3s ease forwards;
}

@keyframes terminalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.trace-shell {
  width: min(760px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: #010801;
  border: 1px solid rgba(0, 255, 80, 0.25);
  border-radius: 8px;
  box-shadow:
    0 0 0 1px rgba(0, 255, 80, 0.08),
    0 0 40px rgba(0, 255, 80, 0.08),
    0 24px 80px rgba(0, 0, 0, 0.8);
  font-family: var(--font-mono);
  animation: terminalSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  overflow: hidden;
  position: relative;
}

@keyframes terminalSlide {
  from { transform: translateY(30px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* Scanline overlay */
.trace-shell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 255, 80, 0.012) 2px,
    rgba(0, 255, 80, 0.012) 4px
  );
  pointer-events: none;
  z-index: 10;
}

.trace-scanline {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 80, 0.3), transparent);
  animation: terminalScan 4s linear infinite;
  pointer-events: none;
  z-index: 11;
}

@keyframes terminalScan {
  0% { top: 0; opacity: 1; }
  90% { opacity: 0.4; }
  100% { top: 100%; opacity: 0; }
}

.trace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: rgba(0, 255, 80, 0.06);
  border-bottom: 1px solid rgba(0, 255, 80, 0.15);
}

.trace-title {
  color: rgba(0, 255, 80, 0.8);
  font-size: 0.76rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.trace-blink {
  animation: traceTextBlink 2.5s ease-in-out infinite;
}

@keyframes traceTextBlink {
  0%, 90%, 100% { opacity: 1; }
  95% { opacity: 0.2; }
}

.trace-close {
  padding: 0.3rem 0.6rem;
  border: 1px solid rgba(0, 255, 80, 0.2);
  background: rgba(0, 255, 80, 0.04);
  color: rgba(0, 255, 80, 0.6);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  transition: all 0.2s ease;
}

.trace-close:hover {
  background: rgba(0, 255, 80, 0.12);
  color: rgba(0, 255, 80, 1);
  border-color: rgba(0, 255, 80, 0.4);
}

.trace-output {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-height: 240px;
  max-height: 50vh;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 255, 80, 0.2) transparent;
}

.trace-output::-webkit-scrollbar {
  width: 4px;
}

.trace-output::-webkit-scrollbar-thumb {
  background: rgba(0, 255, 80, 0.2);
  border-radius: 2px;
}

.trace-line {
  margin: 0;
  color: rgba(0, 255, 80, 0.75);
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  animation: traceLineIn 0.2s ease forwards;
}

@keyframes traceLineIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.trace-sys {
  color: rgba(0, 255, 80, 0.45);
  font-size: 0.76rem;
}

.trace-divider {
  color: rgba(0, 255, 80, 0.2) !important;
  font-size: 0.7rem !important;
}

.trace-cmd {
  color: rgba(0, 255, 80, 1);
  font-weight: bold;
}

.trace-warn {
  color: rgba(255, 180, 0, 0.8) !important;
}

.trace-special {
  color: rgba(0, 200, 255, 0.8) !important;
}

.trace-error {
  color: rgba(255, 60, 60, 0.7) !important;
}

.trace-user {
  color: rgba(180, 255, 180, 0.9) !important;
}

.trace-input-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid rgba(0, 255, 80, 0.12);
  background: rgba(0, 255, 80, 0.02);
}

.trace-prompt {
  color: rgba(0, 255, 80, 0.7);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: text;
}

.trace-input {
  flex: 1;
  border: none;
  background: transparent;
  color: rgba(0, 255, 80, 0.9);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  outline: none;
  caret-color: rgba(0, 255, 80, 0.8);
}

.trace-input::placeholder {
  color: rgba(0, 255, 80, 0.25);
}

/* ─── Mobile ─── */
@media (max-width: 700px) {
  .ledger-shell {
    width: 100%;
    padding: 0.9rem;
  }

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

  .arg-panel,
  .entry-panel {
    padding: 1.4rem;
  }

  .trace-terminal {
    padding: 1rem;
    align-items: flex-end;
  }

  .trace-shell {
    max-height: 70vh;
    border-radius: 12px 12px 0 0;
  }
}
