* {
  box-sizing: border-box;
}

:root {
  --book-width: min(820px, 100%);
  --book-height: clamp(820px, calc(100vh - 96px), 864px);
  --book-page-padding: clamp(30px, 5vw, 58px);
  --book-cover-outline: 0 0 0 8px rgba(151, 122, 84, 0.3);
  --book-left-outline: -8px 0 0 8px rgba(119, 91, 61, 0.22);
  --book-right-outline: 8px 0 0 8px rgba(151, 122, 84, 0.22);
  --book-bottom-outline: 0 8px 0 8px rgba(95, 72, 48, 0.13);
  --book-drop-shadow: 0 30px 58px rgba(48, 38, 28, 0.2);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.5;
  color: #221d18;
  background:
    linear-gradient(rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0)),
    linear-gradient(115deg, #d8c8ac, #b9a17e 54%, #90795c);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(75, 61, 44, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(75, 61, 44, 0.035) 1px, transparent 1px);
  background-size: 46px 46px;
  opacity: 0.55;
}

.app {
  width: min(1040px, calc(100vw - 32px));
  margin: 0 auto;
  padding: clamp(28px, 5vw, 56px) 0;
}

.screen[hidden] {
  display: none;
}

.screen-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.manual-page,
.device-shell,
.generated-idea {
  position: relative;
  z-index: 0;
  width: var(--book-width);
  height: var(--book-height);
  min-height: var(--book-height);
  border: 1px solid rgba(87, 73, 55, 0.22);
  border-radius: 2px;
  background:
    linear-gradient(90deg, rgba(95, 76, 51, 0.055), transparent 15%, transparent 85%, rgba(95, 76, 51, 0.04)),
    linear-gradient(rgba(89, 73, 53, 0.035) 1px, transparent 1px),
    #fffdf5;
  background-size: 100% 100%, 100% 31px, auto;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.82) inset,
    0 22px 52px rgba(48, 38, 28, 0.22);
}

.manual-page > *,
.device-shell > *,
.generated-idea > * {
  position: relative;
  z-index: 2;
}

.manual-page::before,
.device-shell::before,
.generated-idea::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background:
    radial-gradient(ellipse 64px 84% at -16px 50%, rgba(39, 28, 19, 0.16), rgba(62, 46, 30, 0.085) 42%, rgba(90, 72, 49, 0.026) 70%, transparent 88%),
    linear-gradient(180deg, rgba(52, 39, 25, 0.07), transparent 13%, transparent 88%, rgba(52, 39, 25, 0.08)),
    linear-gradient(90deg, rgba(42, 30, 20, 0.105), rgba(57, 42, 28, 0.06) 5%, rgba(92, 74, 51, 0.028) 13%, transparent 24%, transparent 87%, rgba(255, 255, 255, 0.06)),
    linear-gradient(90deg, rgba(50, 38, 26, 0.075), rgba(255, 255, 255, 0.24) 7.5%, transparent 11%, transparent 91.6%, rgba(60, 48, 35, 0.03) 92.6%, transparent 93.6%);
  opacity: 0.62;
  z-index: 1;
}

.device-shell::after,
.generated-idea::after {
  content: "";
  position: absolute;
  top: -8px;
  bottom: -10px;
  left: -26px;
  width: 26px;
  border: 1px solid rgba(56, 42, 29, 0.2);
  border-right: 0;
  border-radius: 3px 0 0 3px;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(55, 39, 25, 0.34), rgba(122, 96, 65, 0.3) 42%, rgba(150, 124, 87, 0.2)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 18%, transparent 82%, rgba(45, 32, 21, 0.13)),
    linear-gradient(145deg, #b99e78, #9f805b);
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.14) inset,
    0 -2px 0 rgba(54, 40, 28, 0.1) inset,
    -5px 16px 32px rgba(48, 38, 28, 0.2);
  opacity: 0.86;
  z-index: 0;
}

.cover-page {
  overflow: hidden;
  border-color: rgba(53, 42, 31, 0.24);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0)),
    linear-gradient(90deg, rgba(61, 45, 33, 0.18), rgba(255, 255, 255, 0.02) 12%, rgba(255, 255, 255, 0) 48%, rgba(255, 255, 255, 0.05) 86%, rgba(47, 35, 26, 0.1)),
    linear-gradient(145deg, #cab393, #b79c79 56%, #a18663);
  background-size: 100% 100%, 100% 100%, auto;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.42) inset,
    0 2px 0 rgba(255, 255, 255, 0.1) inset,
    var(--book-cover-outline),
    var(--book-left-outline),
    var(--book-right-outline),
    var(--book-bottom-outline),
    var(--book-drop-shadow);
}

.cover-page::before {
  background:
    linear-gradient(90deg, rgba(26, 18, 10, 0.15), transparent 11%, transparent 85%, rgba(255, 255, 255, 0.12)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08), transparent 18%, transparent 82%, rgba(37, 26, 18, 0.08));
  opacity: 0.8;
}

.cover-page::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 22px;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(58, 42, 28, 0.3), rgba(255, 248, 238, 0.08) 45%, rgba(255, 255, 255, 0.02) 68%, rgba(35, 25, 17, 0.12));
  box-shadow:
    1px 0 0 rgba(255, 255, 255, 0.2) inset,
    -1px 0 0 rgba(42, 30, 20, 0.16) inset;
  opacity: 0.55;
}

.device-shell,
.generated-idea {
  border-color: rgba(62, 48, 33, 0.28);
  background:
    linear-gradient(180deg, rgba(58, 44, 29, 0.105), transparent 13%, transparent 87%, rgba(58, 44, 29, 0.12)),
    linear-gradient(90deg, rgba(63, 45, 29, 0.18), rgba(95, 76, 51, 0.075) 7%, transparent 19%, transparent 84%, rgba(95, 76, 51, 0.055)),
    linear-gradient(rgba(89, 73, 53, 0.035) 1px, transparent 1px),
    #fffdf5;
  background-size: 100% 100%, 100% 100%, 100% 31px, auto;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 -1px 0 rgba(75, 58, 38, 0.1) inset,
    0 3px 0 -1px rgba(255, 255, 255, 0.42),
    var(--book-cover-outline),
    var(--book-left-outline),
    var(--book-right-outline),
    var(--book-bottom-outline),
    var(--book-drop-shadow);
}

.manual-page {
  margin: 0 auto;
  padding: var(--book-page-padding);
}

.eyebrow {
  margin: 0 0 14px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.76rem;
  font-weight: 700;
  color: #74614b;
  letter-spacing: 0;
  text-transform: uppercase;
}

.intro h1 {
  max-width: 680px;
  margin: 0;
  font-size: clamp(2.7rem, 8vw, 5.2rem);
  line-height: 0.98;
  color: #211b16;
  overflow-wrap: anywhere;
}

.subtitle {
  max-width: 620px;
  margin: 16px 0 0;
  font-size: clamp(1.2rem, 2.5vw, 1.65rem);
  color: #574839;
}

.intro-copy {
  display: grid;
  gap: 13px;
  max-width: 660px;
  margin-top: 34px;
  font-size: clamp(1rem, 2vw, 1.17rem);
  color: #493c30;
}

.intro-copy p {
  margin: 0;
}

.manual-page .screen-actions {
  justify-content: flex-end;
  margin-top: clamp(42px, 8vw, 86px);
}

button {
  appearance: none;
  border: 1px solid #4f4438;
  border-radius: 4px;
  padding: 12px 18px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fffdf5;
  background: #3f352b;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.24);
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #2f281f;
}

button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.24);
}

button:disabled {
  border-color: #b2a895;
  color: #786f61;
  background: #d7cfbf;
  box-shadow: none;
  cursor: not-allowed;
}

.secondary-button {
  border-color: #8a7b66;
  color: #2d261f;
  background: #efe6d2;
}

.secondary-button:hover:not(:disabled) {
  background: #f7efdd;
}

.text-button {
  border-color: transparent;
  color: #4d4135;
  background: transparent;
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.text-button:hover:not(:disabled) {
  color: #211b16;
  background: rgba(255, 253, 245, 0.58);
}

.text-button:active:not(:disabled) {
  transform: none;
  box-shadow: none;
}

.apparatus-panel {
  display: grid;
  justify-items: center;
  min-height: var(--book-height);
  background: transparent;
}

.device-shell {
  align-self: start;
  margin: 0 auto;
  padding: var(--book-page-padding);
}

.machine-layout {
  display: block;
}

.machine-face h2 {
  max-width: 620px;
  margin: 0 0 18px;
  font-size: clamp(2rem, 5vw, 3.8rem);
  line-height: 1.03;
}

.apparatus-copy {
  max-width: 560px;
  margin: 0 0 28px;
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  color: #493c30;
}

.control-card {
  max-width: 560px;
  margin: 0 0 18px;
  padding: 18px 0 0;
  border-top: 1px solid rgba(84, 70, 52, 0.2);
  color: #5f5142;
}

.control-card p {
  margin: 0;
}

.machine-note {
  min-height: 1.4em;
}

.workbench-stack {
  padding: 18px 0 0;
  border-top: 1px solid rgba(84, 70, 52, 0.2);
  color: #756653;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.workbench-stack::before {
  content: "Page includes";
  display: block;
  margin-bottom: 12px;
  color: #574839;
}

.workbench-stack span {
  display: block;
  padding: 7px 0;
  border-top: 1px solid rgba(84, 70, 52, 0.12);
}

.device-actions {
  justify-content: flex-end;
  align-items: center;
  gap: 12px 18px;
  margin-top: clamp(36px, 7vw, 72px);
}

.page-prompt {
  margin: 0;
  margin-right: 4px;
  color: #493c30;
  font-size: 1.05rem;
  text-align: left;
}

.status,
.copy-status {
  margin: 0;
  color: #625444;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.94rem;
}

.results {
  display: grid;
  justify-items: center;
  min-height: var(--book-height);
  background: transparent;
}

.results-area {
  width: var(--book-width);
  margin: 0 auto;
}

.generated-idea {
  display: flex;
  flex-direction: column;
  grid-column: 1;
  margin: 0;
  padding: var(--book-page-padding);
}

.generated-idea h2 {
  margin: 0 0 20px;
  font-size: clamp(1.45rem, 3vw, 2.15rem);
  line-height: 1.08;
}

.generated-idea .idea-text {
  max-width: 720px;
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.15rem);
  line-height: 1.36;
  color: #211b16;
}

.generated-idea .helper-text {
  max-width: 620px;
  margin: 20px 0 0;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.98rem;
  color: #645545;
}

.generated-idea .selection-list {
  margin-top: 34px;
}

.page-footer {
  display: grid;
  justify-items: stretch;
  gap: 12px;
  margin-top: auto;
  padding-top: 30px;
  text-align: right;
}

.page-label,
.quiet-serial {
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  line-height: 1.2;
  word-break: break-word;
}

.page-label {
  color: #5d4e3f;
  font-size: 0.86rem;
  justify-self: end;
  margin-top: 2px;
  margin-right: -10px;
  margin-bottom: -2px;
}

.quiet-serial {
  color: #8b7c68;
  font-size: 0.68rem;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  justify-self: center;
  gap: 10px;
  max-width: 100%;
  transform: translateX(-34px);
}

.result-actions button {
  width: auto;
  min-width: 0;
}

.copy-status {
  justify-self: center;
  width: 100%;
  min-height: 1.4em;
  margin-top: 0;
  text-align: center;
}

.selection-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.selection-list div {
  display: grid;
  gap: 4px;
  grid-template-columns: minmax(150px, 0.42fr) minmax(0, 1fr);
  padding: 7px 0;
  border-top: 1px solid rgba(84, 70, 52, 0.18);
}

.label {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: #6d5d4a;
  text-transform: uppercase;
}

.item-name {
  margin: 0;
  color: #2f281f;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(40, 34, 27, 0.44);
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-dialog {
  width: min(100%, 430px);
  padding: 24px;
  border: 1px solid rgba(87, 73, 55, 0.26);
  border-radius: 3px;
  color: #2d261f;
  background: #fffdf5;
  box-shadow: 0 24px 54px rgba(25, 19, 14, 0.3);
}

.confirm-dialog h2 {
  margin: 0 0 12px;
  font-size: 1.55rem;
  line-height: 1.1;
}

.confirm-dialog p {
  margin: 0 0 10px;
  color: #5b4d3e;
}

.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.empty,
.error {
  margin: 0;
  font-size: 1.1rem;
  color: #5b4d3e;
}

.error {
  color: #a73527;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-width: 88px;
  border: 1px solid #cfd7e6;
  border-radius: 4px;
  padding: 11px 12px;
  font: inherit;
  color: #202124;
  background: #ffffff;
}

.controls,
.review-controls,
.serial-replay-controls,
.copy-actions {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
}

.count-control,
.source-control,
.serial-control {
  display: grid;
  gap: 6px;
  min-width: min(100%, 220px);
}

.serial-replay,
.review-summary,
.sample-card {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid #d9dde5;
  border-radius: 6px;
  background: #ffffff;
}

.serial-replay h2,
.review-summary h2,
.sample-title {
  margin: 0 0 12px;
  font-size: 1rem;
}

.serial-replay-result,
.review-results,
.sample-rows {
  display: grid;
  gap: 12px;
}

.review-summary-meta,
.sample-meta {
  display: grid;
  gap: 8px 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin: 0 0 14px;
}

.review-table-counts,
.sample-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

.review-table-counts li,
.sample-rows li {
  padding: 10px;
  border: 1px solid #e4e7ec;
  border-radius: 5px;
  background: #fbfcfe;
}

.sample-rows li {
  display: grid;
  grid-template-columns: minmax(150px, max-content) minmax(0, 1fr);
  gap: 8px 16px;
  align-items: baseline;
}

.review-summary-meta dt,
.sample-meta dt {
  margin: 0 0 2px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #667085;
}

.review-summary-meta dd,
.sample-meta dd {
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  word-break: break-word;
}

.sample-idea {
  margin: 0 0 14px;
  font-size: 1.05rem;
}

.copy-button {
  border: 1px solid #cfd7e6;
  padding: 7px 10px;
  font-size: 0.85rem;
  color: #1f2937;
  background: #f8fbff;
}

.copy-button:hover {
  background: #edf4ff;
}

@media (max-width: 700px) {
  :root {
    --book-height: max(1040px, calc(100vh - 56px));
    --book-page-padding: 24px;
  }

  .app {
    width: min(calc(100vw - 24px), 1040px);
    padding: 28px 0;
  }

  .manual-page,
  .device-shell,
  .generated-idea {
    padding: var(--book-page-padding);
  }

  .intro h1 {
    font-size: clamp(2.15rem, 11.5vw, 2.75rem);
  }

  .screen-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .machine-layout {
    grid-template-columns: 1fr;
  }

  .apparatus-panel {
    min-height: var(--book-height);
  }

  .workbench-stack {
    display: none;
  }

  .generated-idea {
    grid-column: 1;
  }

  .selection-list div {
    grid-template-columns: 1fr;
  }

  .sample-rows li {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  .text-button {
    width: auto;
    align-self: center;
  }

  .result-actions {
    width: 100%;
    transform: none;
  }

  .result-actions button {
    width: 100%;
  }

  .page-label {
    margin-right: 0;
  }

  .serial-replay-controls,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }
}
