:root {
  color-scheme: dark;
  --bg: #000000;
  --panel: rgba(12, 13, 15, 0.96);
  --panel-border: rgba(255, 255, 255, 0.06);
  --ink: #f5f7fa;
  --muted: #98a1ab;
  --accent: #d5dbe2;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  --radius: 20px;
  --gap: 12px;
  --app-height: 100dvh;
  --display-height: 320px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(66, 71, 78, 0.18), transparent 18%),
    linear-gradient(180deg, #050607 0%, #000000 100%);
  color: var(--ink);
}

body {
  overflow: auto;
}

.app-shell {
  width: min(720px, 100%);
  min-height: var(--app-height);
  height: auto;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: var(--gap);
  padding:
    calc(env(safe-area-inset-top, 0px) + 12px)
    12px
    calc(env(safe-area-inset-bottom, 0px) + 12px);
}

.input-panel,
.display-panel,
.nav-panel,
.saved-panel,
.saved-header {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.input-panel {
  padding: 10px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.display-panel {
  height: var(--display-height);
  min-height: 260px;
  max-height: 520px;
  padding: 12px;
}

.nav-panel {
  padding: 10px;
  margin-top: 40px;
}

.input-box,
.display-box {
  width: 100%;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(24, 27, 31, 0.98);
  line-height: 1.6;
}

.input-box {
  display: block;
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  padding: 10px 14px;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  appearance: none;
  -webkit-appearance: none;
}

.input-box::placeholder {
  color: var(--muted);
  opacity: 1;
}

.input-box:focus {
  outline: 3px solid rgba(197, 204, 211, 0.12);
  border-color: rgba(197, 204, 211, 0.2);
}

.clear-button {
  height: 44px;
  min-width: 64px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(20, 22, 25, 0.98);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1;
  white-space: nowrap;
  appearance: none;
  -webkit-appearance: none;
}

.clear-button:focus {
  outline: 3px solid rgba(197, 204, 211, 0.12);
  border-color: rgba(197, 204, 211, 0.2);
}

.display-box {
  height: 100%;
  padding: 16px 16px 20px;
  display: block;
}

.final-text {
  height: 100%;
  overflow-y: auto;
  color: var(--ink);
  font-size: clamp(1.1rem, 3.8vw, 1.45rem);
  line-height: 1.8;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.clear-button {
  touch-action: manipulation;
}

.nav-link-button,
.saved-back,
.detail-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(20, 22, 25, 0.98);
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  line-height: 1;
  appearance: none;
  -webkit-appearance: none;
}

.nav-link-button {
  width: 100%;
}

.saved-body {
  overflow: auto;
}

.saved-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top, 0px) + 12px)
    12px
    calc(env(safe-area-inset-bottom, 0px) + 12px);
  display: grid;
  gap: 12px;
}

.saved-header,
.saved-panel {
  padding: 16px;
}

.saved-header {
  display: grid;
  gap: 12px;
}

.saved-eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.saved-title,
.saved-group-head h2,
.detail-title {
  margin: 0;
}

.saved-group + .saved-group {
  margin-top: 16px;
}

.saved-notice {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(69, 54, 21, 0.42);
  color: #f1d8a5;
  line-height: 1.6;
}

.saved-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.saved-group-head {
  margin-bottom: 10px;
}

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

.saved-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(17, 19, 22, 0.98);
  color: inherit;
  text-decoration: none;
}

.saved-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.saved-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(197, 204, 211, 0.14);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 600;
}

.saved-card-date,
.detail-date,
.saved-empty,
.detail-status {
  color: var(--muted);
  font-size: 0.92rem;
}

.saved-card-title {
  font-size: 1rem;
}

.saved-card-preview,
.detail-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.saved-card-preview {
  color: var(--muted);
  line-height: 1.6;
}

.detail-head {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.saved-back-inline {
  width: fit-content;
}

.detail-body {
  min-height: 220px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: rgba(17, 19, 22, 0.98);
  line-height: 1.7;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.detail-button {
  min-width: 96px;
}

.detail-button-danger {
  color: #f08f86;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .app-shell {
    padding:
      calc(env(safe-area-inset-top, 0px) + 8px)
      8px
      calc(env(safe-area-inset-bottom, 0px) + 8px);
    gap: 8px;
  }

  .input-panel {
    padding: 8px;
  }

  .input-row {
    gap: 6px;
  }

  .display-panel {
    min-height: 250px;
    max-height: 460px;
    padding: 8px;
  }

  .nav-panel,
  .saved-header,
  .saved-panel {
    padding: 12px;
  }

  .nav-panel {
    margin-top: 56px;
  }

  .input-box {
    height: 42px;
    min-height: 42px;
    max-height: 42px;
    padding: 9px 12px;
  }

  .clear-button {
    height: 42px;
    min-width: 58px;
    padding: 0 12px;
  }

  .display-box {
    padding: 14px 14px 18px;
  }

  .final-text {
    font-size: 1.02rem;
  }

  .saved-shell {
    padding:
      calc(env(safe-area-inset-top, 0px) + 8px)
      8px
      calc(env(safe-area-inset-bottom, 0px) + 8px);
  }

  .detail-actions {
    flex-wrap: wrap;
  }

}
