:root {
  color-scheme: light;
  --paper: #fffaf2;
  --panel: #ffffff;
  --ink: #181512;
  --line: #2a2119;
  --soft-line: #ded6ca;
  --muted: #73685b;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --section: #2f241a;
  --field: #fffdf8;
  --shadow: 0 14px 34px rgb(32 24 16 / 13%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ece7df;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.home {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 28px 16px;
}

.home h1 {
  margin: 0 0 20px;
  font-size: 28px;
  letter-spacing: 0;
}

.open-sheet label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.open-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.open-row input,
.open-row button,
.new-sheet-button {
  min-height: 48px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  font: inherit;
}

.open-row input {
  padding: 0 12px;
}

.open-row button,
.new-sheet-button {
  padding: 0 18px;
  background: var(--section);
  color: #fff;
  cursor: pointer;
}

.new-sheet-button {
  min-width: 104px;
}

.form-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.form-error {
  margin: 10px 0 0;
  color: #b42318;
  font-size: 14px;
  font-weight: 700;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 9px 12px;
  background: rgb(255 250 242 / 96%);
  border-bottom: 1px solid var(--soft-line);
  backdrop-filter: blur(10px);
}

.toolbar-close {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--soft-line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.toolbar-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

#save-state {
  margin-left: auto;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(24 21 18 / 55%);
}

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

.modal {
  width: min(100%, 420px);
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.modal-body a {
  color: var(--accent-strong);
  font-weight: 700;
  word-break: break-all;
}

.modal-body input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.modal-actions button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.sheet {
  display: grid;
  gap: 22px;
  padding: 14px 10px 46px;
}

.page {
  width: 100%;
  overflow: hidden;
  padding: 18px 12px;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.page-title {
  display: grid;
  margin-bottom: 14px;
  text-align: left;
}

.page-title h1 {
  margin: 0;
  padding: 0 0 12px;
  border-bottom: 2px solid var(--line);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  font-style: italic;
  line-height: 1;
  letter-spacing: 0;
}

.sheet-table,
.sheet-table tbody,
.sheet-table tr,
.sheet-table td {
  display: block;
  width: 100%;
}

.sheet-table {
  border: 0;
  border-collapse: collapse;
}

.sheet-table tr {
  overflow: hidden;
  margin: 0 0 14px;
  border: 1px solid var(--soft-line);
  border-radius: 10px;
  background: var(--panel);
}

.sheet-table td {
  min-height: 48px;
  padding: 0;
  border: 0;
  border-top: 1px solid #eee7dd;
  background: var(--panel);
}

.sheet-table td:first-child,
.sheet-table tr:first-child td {
  border-top: 0;
}

.label {
  text-align: left;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0;
}

.side,
.top-label {
  min-height: 48px;
  padding: 13px 12px 11px;
  border: 0;
  border-radius: 0;
  background: var(--section);
  color: #fff;
  line-height: 1.1;
}

.inline-label {
  min-height: 46px;
  padding: 12px 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
  font-style: italic;
  line-height: 1.2;
}

.total-insights-label,
.total-insights-field {
  border-top: 1px solid var(--soft-line);
}

.field-cell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 9px 10px 10px;
}

.field-cell::before {
  content: attr(data-label);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.identity-name {
  min-height: 66px;
}

.identity-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 9px 10px 10px;
}

.identity-field label,
.stat label {
  display: block;
  font-weight: 800;
}

.identity-field label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.stat {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 124px;
  gap: 8px;
  padding: 11px 10px;
  text-align: left;
}

.stat label {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  font-style: italic;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.stat input:not([type="checkbox"]) {
  min-height: 42px;
  text-align: center;
}

.pip-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 7px;
  padding-top: 9px;
}

.tall {
  min-height: 78px;
}

.textarea-cell {
  min-height: 170px;
  padding: 10px;
}

.textarea-cell > .label {
  display: block;
  padding: 0 0 8px;
  line-height: 1.15;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--soft-line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  font: 500 16px Arial, Helvetica, sans-serif;
  outline: none;
}

input {
  min-height: 42px;
  padding: 7px 9px;
  line-height: 1.25;
}

textarea {
  min-height: 118px;
  padding: 9px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  background: #f2fffc;
  box-shadow: 0 0 0 3px rgb(15 118 110 / 16%);
}

input[type="checkbox"] {
  width: 100%;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 7px;
  accent-color: var(--accent);
}

.supply {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.lamp-row,
.inline-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  min-height: 34px;
  font-size: 15px;
  font-weight: 800;
}

.lamp-row {
  grid-template-columns: auto repeat(3, 34px);
}

.inline-field span {
  flex: 0 0 auto;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.inline-field input {
  min-height: 34px;
}

@media (min-width: 520px) {
  .open-row {
    grid-template-columns: 1fr auto;
  }
}

@media (min-width: 760px) {
  .home {
    margin-top: 10vh;
    padding-inline: 0;
  }

  .home h1 {
    font-size: 32px;
  }

  .toolbar {
    gap: 18px;
    padding: 10px 18px;
  }

  #save-state {
    font-size: 14px;
  }

  .sheet {
    justify-items: center;
    gap: 26px;
    padding: 28px 12px 60px;
  }

  .page {
    width: min(100%, 900px);
    min-height: 1272px;
    padding: 46px 54px;
    border-radius: 0;
  }

  .page-title {
    margin-bottom: 0;
    text-align: center;
  }

  .page-title h1 {
    padding: 14px 0 16px;
    border: 3px solid var(--line);
    border-bottom: 0;
    font-size: 34px;
  }

  .sheet-table {
    display: table;
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    border: 3px solid var(--line);
  }

  .sheet-table tbody {
    display: table-row-group;
  }

  .sheet-table tr {
    display: table-row;
    overflow: visible;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .sheet-table td {
    display: table-cell;
    width: auto;
    height: 36px;
    min-height: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-top: 1px solid var(--line);
    background: transparent;
    vertical-align: middle;
  }

  .field-cell {
    display: table-cell;
    padding: 0;
  }

  .field-cell::before {
    content: none;
  }

  .sheet-table tr:has(.side) td,
  .sheet-table tr:has(.top-label) td {
    border-top-width: 3px;
  }

  .label {
    text-align: center;
    font-size: 23px;
  }

  .side {
    width: 25%;
    padding: 6px;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    line-height: 1.15;
  }

  .top-label {
    height: 48px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
  }

  .inline-label {
    min-height: 0;
    padding: 0 7px;
    font-size: 18px;
    vertical-align: middle;
  }

  .identity-name {
    height: 64px;
    min-height: 0;
  }

  .identity-field {
    display: table-cell;
    padding: 0 8px;
  }

  .identity-field label {
    display: inline-block;
    width: 112px;
    padding-top: 0;
    color: var(--ink);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 18px;
    font-style: italic;
    line-height: 1.1;
    text-transform: none;
    vertical-align: middle;
  }

  .identity-field input {
    width: calc(100% - 118px);
    vertical-align: middle;
  }

  .stat {
    display: table-cell;
    height: 130px;
    min-height: 0;
    padding: 8px;
    text-align: center;
  }

  .stat label {
    display: block;
    min-height: 42px;
    margin-bottom: 6px;
    font-size: 20px;
    line-height: 1.05;
  }

  .pip-row {
    display: flex;
    justify-content: center;
    gap: 7px;
    padding-top: 6px;
  }

  .tall {
    height: 86px;
    min-height: 0;
  }

  .textarea-cell {
    height: 180px;
    min-height: 0;
    padding: 0;
  }

  input,
  textarea {
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .stat input:not([type="checkbox"]) {
    height: 34px;
    min-height: 34px;
  }

  input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-height: 18px;
  }

  textarea {
    height: calc(100% - 38px);
  }

  .lamp-row,
  .inline-field {
    display: flex;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 18px;
    font-style: italic;
  }

  .lamp-row {
    grid-template-columns: none;
  }
}

@media (min-width: 1500px) {
  .sheet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    max-width: 1840px;
    margin: 0 auto;
  }

  .page {
    width: 100%;
    min-height: auto;
    aspect-ratio: 210 / 297;
    padding: clamp(28px, 2.6vw, 46px) clamp(32px, 3vw, 54px);
  }
}
