:root{
  --paper: #ede2c4;
  --paper-2: #e4d5ab;
  --paper-edge: #d9c691;
  --ink: #1c3b30;
  --ink-2: #142a22;
  --navy: #1a2a4a;
  --brass: #93702f;
  --brass-light: #b08d43;
  --red: #7a2426;
  --green-pos: #1c5c3a;
  --hairline: rgba(28,59,48,0.35);
}

*{ box-sizing: border-box; }

html, body{
  margin:0;
  padding:0;
  min-height:100%;
  background: #cabf9c;
}

body{
  font-family: 'EB Garamond', serif;
  color: var(--ink-2);
  padding: 2.5rem 1rem 5rem;
  display:flex;
  justify-content:center;
  /* subtle paper fiber under the guilloché */
  background-image:
    repeating-linear-gradient(115deg, rgba(0,0,0,0.015) 0px, rgba(0,0,0,0.015) 1px, transparent 1px, transparent 3px);
}

.sheet{
  width: 100%;
  max-width: 980px;
  position: relative;
}

/* ============ CERTIFICATE FRAME ============ */
.certificate{
  position: relative;
  background:
    radial-gradient(ellipse at top left, rgba(255,255,255,0.35), transparent 60%),
    linear-gradient(var(--paper), var(--paper-2));
  padding: 34px;
  box-shadow:
    0 2px 0 rgba(255,255,255,0.4) inset,
    0 25px 60px -20px rgba(20,30,20,0.55),
    0 2px 8px rgba(20,30,20,0.25);
}

/* outer engraved rule */
.frame-outer{
  border: 3px double var(--ink);
  padding: 10px;
}
.frame-inner{
  border: 1px solid var(--brass);
  outline: 1px solid var(--ink);
  outline-offset: 5px;
  padding: 34px clamp(16px, 4vw, 46px) 40px;
  position: relative;
  background-image:
    /* guilloché-style fine engraved pattern, layered conic + radial, very low opacity */
    repeating-conic-gradient(from 0deg at 50% 0%, rgba(28,59,48,0.05) 0deg 2deg, transparent 2deg 8deg),
    repeating-radial-gradient(circle at 50% 0%, rgba(28,59,48,0.04) 0px, rgba(28,59,48,0.04) 1px, transparent 2px, transparent 9px);
  background-size: 140px 140px, 46px 46px;
  background-repeat: repeat, repeat;
}

/* corner flourishes */
.corner{
  position:absolute;
  width: 74px;
  height: 74px;
  pointer-events:none;
  z-index: 3;
}
.corner svg{ width:100%; height:100%; display:block; }
.corner.tl{ top:-3px; left:-3px; }
.corner.tr{ top:-3px; right:-3px; transform: scaleX(-1); }
.corner.bl{ bottom:-3px; left:-3px; transform: scaleY(-1); }
.corner.br{ bottom:-3px; right:-3px; transform: scale(-1,-1); }

.cert-number{
  position:absolute;
  top: 10px;
  right: 26px;
  font-family:'Courier Prime', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--brass);
  z-index: 4;
}
.cert-number-left{
  left: 26px;
  right:auto;
}

/* ============ HEADER ============ */
.masthead{
  text-align:center;
  padding-bottom: 18px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--hairline);
  position:relative;
}
.eyebrow{
  font-family:'Cinzel', serif;
  font-size: 0.68rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 10px;
}
h1{
  font-family: 'Cinzel Decorative', 'Cinzel', serif;
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  letter-spacing: 0.03em;
  margin: 0;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}
.subtitle{
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink);
  margin-top: 10px;
  letter-spacing: 0.02em;
}
.rule-orn{
  margin: 14px auto 0;
  width: 220px;
  height: 14px;
  opacity: 0.75;
}

/* ============ LAYOUT ============ */
.body-grid{
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 30px;
}
.body-grid > section{ min-width: 0; }
@media (max-width: 800px){
  .body-grid{ grid-template-columns: 1fr; gap: 20px; }
}

.section-title{
  font-family:'Cinzel', serif;
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
  display:flex;
  align-items:center;
  gap: 10px;
}
.section-title::before, .section-title::after{
  content:'';
  flex: 0 0 20px;
  height: 1px;
  background: var(--brass);
}
.section-title::after{ display:none; }

/* ============ FORM: fill-in-the-blank styling ============ */
.field{
  margin-bottom: 18px;
}
.field label{
  display:block;
  font-family:'Cinzel', serif;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 6px;
}
.field .hint{
  display:block;
  font-family:'EB Garamond', serif;
  font-style: italic;
  font-size: 0.78rem;
  color: #5a5138;
  text-transform:none;
  letter-spacing: 0;
  margin-top: 4px;
}
.input-row{
  position: relative;
  display:flex;
  align-items:baseline;
}
.input-row .prefix{
  font-family:'EB Garamond', serif;
  font-size: 1.05rem;
  color: var(--ink);
  margin-right: 6px;
}
input[type="number"], input[type="date"], select{
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px dotted var(--ink);
  font-family: 'Courier Prime', 'EB Garamond', monospace;
  font-size: 1.05rem;
  color: var(--ink-2);
  padding: 4px 4px 6px;
  outline: none;
  appearance: none;
}
select{
  font-family: 'EB Garamond', serif;
  font-size: 1.05rem;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--brass) 50%), linear-gradient(135deg, var(--brass) 50%, transparent 50%);
  background-position: calc(100% - 12px) 12px, calc(100% - 6px) 12px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
input:focus, select:focus{
  border-bottom: 1px solid var(--brass);
  background-color: rgba(147,112,47,0.06);
}
input::-webkit-calendar-picker-indicator{
  filter: sepia(1) saturate(3) hue-rotate(60deg) brightness(0.7);
  cursor:pointer;
}
.two-col{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.warn-inline{
  font-family:'EB Garamond', serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--red);
  margin-top: 6px;
}

/* ============ ADVANCED (collapsible) ============ */
details.advanced{
  margin-top: 8px;
  border-top: 1px solid var(--hairline);
  padding-top: 14px;
}
details.advanced summary{
  cursor: pointer;
  font-family:'Cinzel', serif;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brass);
  list-style: none;
  display:flex;
  align-items:center;
  gap:8px;
}
details.advanced summary::-webkit-details-marker{ display:none; }
details.advanced summary::before{
  content: '\2756';
  font-size: 0.8rem;
}
details.advanced[open] summary::before{ content: '\2757'; }
.advanced-note{
  font-style: italic;
  font-size: 0.78rem;
  color: #5a5138;
  margin: 10px 0 16px;
}

/* ============ RESULTS SIDE ============ */
.seal-wrap{
  display:flex;
  justify-content:center;
  margin-bottom: 22px;
}
.seal{
  width: 210px;
  height: 210px;
  border-radius: 50%;
  position: relative;
  display:flex;
  align-items:center;
  justify-content:center;
  background:
    repeating-conic-gradient(from 0deg, rgba(255,255,255,0.5) 0deg 1deg, transparent 1deg 6deg),
    radial-gradient(circle at 50% 40%, #f4ead0, #d8c68f 70%, #b79b5c 100%);
  border: 3px double var(--brass);
  box-shadow: 0 6px 18px rgba(30,20,0,0.35), inset 0 0 0 8px rgba(255,255,255,0.15);
}
.seal-inner{
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  text-align:center;
  padding: 8px;
  background: rgba(237,226,196,0.55);
}
.seal-label{
  font-family:'Cinzel', serif;
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}
.seal-value{
  font-family:'Cinzel Decorative','Cinzel', serif;
  font-size: 1.55rem;
  font-weight: 700;
  margin: 4px 0;
  line-height: 1.05;
}
.seal-value.pos{ color: var(--green-pos); }
.seal-value.neg{ color: var(--red); }
.seal-sub{
  font-family:'EB Garamond', serif;
  font-style: italic;
  font-size: 0.8rem;
  color: var(--ink);
}

.metrics-row{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}
.metric-box{
  border: 1px solid var(--hairline);
  padding: 10px 12px;
  text-align:center;
  background: rgba(255,255,255,0.18);
}
.metric-box .m-label{
  font-family:'Cinzel', serif;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass);
}
.metric-box .m-value{
  font-family:'Cinzel', serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-2);
  margin-top: 4px;
}
.metric-box .m-value.pos{ color: var(--green-pos); }
.metric-box .m-value.neg{ color: var(--red); }

/* cash flow ledger, printed-clause style */
.ledger{
  border: 1px solid var(--hairline);
  padding: 16px 18px;
  background: rgba(255,255,255,0.12);
}
.ledger-line{
  display:flex;
  justify-content:space-between;
  padding: 7px 0;
  border-bottom: 1px dotted var(--hairline);
  font-size: 0.95rem;
}
.ledger-line:last-child{ border-bottom:none; }
.ledger-line .lbl{ color: var(--ink); }
.ledger-line .lbl small{
  display:block;
  font-style: italic;
  font-size: 0.72rem;
  color:#5a5138;
}
.ledger-line .amt{
  font-family:'Courier Prime', monospace;
  font-weight: 700;
}
.ledger-line .amt.neg{ color: var(--red); }
.ledger-line .amt.pos{ color: var(--green-pos); }
.ledger-line.total{
  border-top: 1px solid var(--ink);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 1.05rem;
}

/* cross-check yield table */
.yield-table{
  margin-top: 22px;
  border: 1px solid var(--hairline);
  background: rgba(255,255,255,0.12);
}
.yield-table table{
  width:100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.yield-table th, .yield-table td{
  padding: 8px 10px;
  text-align:right;
  border-bottom: 1px dotted var(--hairline);
}
.yield-table th:first-child, .yield-table td:first-child{ text-align:left; }
.yield-table th{
  font-family:'Cinzel', serif;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
  font-weight: 600;
}
.yield-table tr:last-child td{ border-bottom:none; }
.flag{
  color: var(--red);
  font-weight: 700;
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}
.ok{
  color: var(--green-pos);
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
}
.dash{ color: #948a6c; }

.cross-check-note{
  margin-top: 14px;
  font-size: 0.85rem;
  font-style: italic;
  padding: 10px 12px;
  border-left: 3px solid var(--brass);
  background: rgba(255,255,255,0.15);
}
.cross-check-note.bad{
  border-left-color: var(--red);
  color: var(--red);
}
.cross-check-note.good{
  border-left-color: var(--green-pos);
}

.footer-strip{
  margin-top: 30px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
  display:flex;
  justify-content:space-between;
  font-family:'Cinzel', serif;
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
  flex-wrap: wrap;
  gap: 8px;
}

.error-banner{
  background: rgba(122,36,38,0.1);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 12px 16px;
  font-style: italic;
  margin-bottom: 20px;
  text-align:center;
}

/* ============ DOG-EAR (folded corner of the certificate itself) ============ */
.dog-ear{
  position: absolute;
  left: 0;
  bottom: 0;
  width: 66px;
  height: 66px;
  z-index: 20;
  text-decoration: none;
  display:block;
  overflow: hidden;
  transition: width 0.18s ease, height 0.18s ease;
}
.dog-ear:hover{
  width: 78px;
  height: 78px;
}
.dog-ear::before{
  /* the curled flap: a right triangle pinned to the bottom-left corner */
  content:'';
  position:absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
  background: linear-gradient(225deg, var(--paper-2) 0%, var(--paper-edge) 55%, #c2ac79 100%);
  box-shadow: inset -2px 2px 5px rgba(255,255,255,0.5), inset 2px -2px 6px rgba(20,30,20,0.25);
  filter: drop-shadow(4px -4px 6px rgba(20,30,20,0.35));
}
.dog-ear::after{
  /* hairline crease along the fold */
  content:'';
  position:absolute;
  left: 0;
  bottom: 0;
  width: 141%;
  height: 1px;
  background: var(--hairline);
  transform: rotate(45deg);
  transform-origin: bottom left;
}
.dog-ear .dog-ear-label{
  position:absolute;
  left: -13px;
  bottom: 16px;
  font-family:'Cinzel', serif;
  font-size: 0.5rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
  transform: rotate(45deg);
  transform-origin: bottom left;
  white-space: nowrap;
  pointer-events:none;
}

/* ============ HOLDING NAME (single line, top of form) ============ */
.holding-name-row{
  display:flex;
  align-items:baseline;
  gap: 10px;
  margin-bottom: 22px;
}
.holding-name-row label{
  font-family:'Cinzel', serif;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  white-space:nowrap;
}
.holding-name-row input{
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px dotted var(--ink);
  font-family: 'Cinzel Decorative', 'Cinzel', serif;
  font-size: 1.05rem;
  color: var(--ink-2);
  padding: 2px 4px 5px;
  outline: none;
}
.holding-name-row input:focus{
  border-bottom: 1px solid var(--brass);
  background-color: rgba(147,112,47,0.06);
}
.holding-name-row input::placeholder{
  font-family:'EB Garamond', serif;
  font-style: italic;
  color: #8a7f5c;
  opacity: 0.8;
}

/* ============ FOOTER SAVE ACTION ============ */
.footer-strip{ align-items:center; }
.footer-save{
  background:none;
  border:none;
  padding:0;
  font-family:'Cinzel', serif;
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.footer-save:hover{ color: var(--ink); }
.footer-status{
  font-style: italic;
  text-transform: none;
  letter-spacing: 0;
  font-family:'EB Garamond', serif;
  font-size: 0.78rem;
  color: var(--green-pos);
}

/* ============ REGISTRY PAGE (index.html) ============ */
.new-holding-row{ display:flex; justify-content:center; margin-bottom: 30px; }
.btn-new{
  display:inline-block;
  background: rgba(255,255,255,0.25);
  border: 1px solid var(--brass);
  color: var(--ink);
  font-family:'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  padding: 11px 26px;
  transition: background 0.15s ease;
}
.btn-new:hover{ background: rgba(147,112,47,0.16); }

.registry-empty{
  font-style: italic; font-size: 0.92rem; color: #5a5138;
  text-align:center; padding: 30px 10px 10px;
}

.registry-row{
  display:flex; align-items:center; justify-content:space-between; gap:16px;
  padding: 14px 2px; border-bottom: 1px dotted var(--hairline); flex-wrap: wrap;
}
.registry-row:last-child{ border-bottom:none; }
.registry-row-main{ display:flex; flex-direction:column; gap:3px; min-width:220px; }
.registry-name{ font-family:'Cinzel', serif; font-size: 0.92rem; color: var(--ink); }
.registry-meta{
  font-family:'Courier Prime', monospace; font-size: 0.78rem; color: #5a5138;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.registry-updated{ font-style: italic; font-size: 0.72rem; color: #8a7f5c; margin-top:1px; }
.registry-row-actions{ display:flex; gap:10px; flex: 0 0 auto; }
.registry-row-actions a, .registry-row-actions button{
  font-family:'Cinzel', serif; font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 7px 13px; border: 1px solid var(--brass); background: rgba(255,255,255,0.25);
  color: var(--ink); text-decoration:none; cursor:pointer;
}
.registry-row-actions a:hover, .registry-row-actions button:hover{ background: rgba(147,112,47,0.16); }
.registry-row-actions button.revoke{ border-color: var(--red); color: var(--red); }
.registry-row-actions button.revoke:hover{ background: rgba(122,36,38,0.08); }

.footer-note{
  margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--hairline);
  text-align:center; font-family:'Cinzel', serif; font-size: 0.6rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--brass);
}

/* the registry page is narrower and uses smaller display type than the certificate */
body.page-registry .sheet{ max-width: 760px; }
body.page-registry h1{ font-size: clamp(1.4rem, 4vw, 2.1rem); }
body.page-registry .subtitle{ font-size: 0.92rem; letter-spacing: normal; }

/* ============ MOBILE ============ */
@media (max-width: 600px){
  body{ padding: 1.25rem 0.4rem 3rem; }
  .certificate{ padding: 16px; }
  .frame-outer{ padding: 6px; }
  .frame-inner{ padding: 26px clamp(10px, 4vw, 20px) 30px; outline-offset: 3px; }
  .corner{ width: 44px; height: 44px; }
  .cert-number{ position: static; display:block; text-align:center; margin-bottom: 4px; font-size: 0.62rem; }
  .cert-number-left{ margin-bottom: 2px; }
  .two-col{ grid-template-columns: 1fr; gap: 4px; }
  .seal{ width: clamp(150px, 55vw, 210px); height: clamp(150px, 55vw, 210px); }
  .seal-inner{ width: 76%; height: 76%; }
  .seal-value{ font-size: 1.3rem; }
  .metrics-row{ gap: 8px; }
  .metric-box{ padding: 8px; }
  .yield-table{ overflow-x: auto; }
  .yield-table table{ font-size: 0.78rem; }
  .yield-table th, .yield-table td{ padding: 6px; }
  .footer-strip{ justify-content:center; text-align:center; font-size: 0.55rem; }
  .dog-ear{ width: 48px; height: 48px; }
  .dog-ear:hover{ width: 56px; height: 56px; }
}
