:root{
  --primary:#2b4a3d;
  --secondary:#f4efe6;
  --accent:#c4a747;
  --accent-dark:#a8892f;
  --indigo:#2c2a5e;
  --faded-red:#b84a3a;
  --paper:#fdfaf2;
  --ink:#3a3329;
  --copper:#a4673a;
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}

html,body{
  margin:0;
  height:100%;
  height:100dvh;
  background:var(--primary);
  font-family:"Georgia","Times New Roman",serif;
  color:var(--ink);
  overflow:hidden;
}

body{
  padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.book{
  position:relative;
  max-width:520px;
  margin:0 auto;
  height:var(--vvh,100%);
  max-height:var(--vvh,100%);
  background:
    linear-gradient(180deg,#30503f 0%,#243f33 100%);
  border-radius:6px 12px 12px 6px;
  box-shadow:
    inset 3px 0 8px rgba(0,0,0,.35),
    0 12px 30px rgba(0,0,0,.45);
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

.ribbon{
  position:absolute;
  top:0;
  left:50%;
  transform:translateX(-50%);
  width:22px;
  height:64px;
  background:linear-gradient(90deg,#c23a32,#d84a40 50%,#b0342c);
  border-radius:0 0 6px 6px;
  box-shadow:0 2px 4px rgba(0,0,0,.3);
  z-index:40;
}
.ribbon::after{
  content:"";
  position:absolute;
  bottom:-20px;
  left:0;
  width:0;height:0;
  border-left:11px solid transparent;
  border-right:11px solid transparent;
  border-top:20px solid #d84a40;
}

/* Masthead */
.masthead{
  background:
    repeating-linear-gradient(45deg,rgba(255,255,255,.02) 0 2px,transparent 2px 8px),
    var(--primary);
  padding:calc(14px + env(safe-area-inset-top)) 18px 14px;
  text-align:center;
  border-bottom:3px solid var(--accent-dark);
}
.app-name{
  margin:0;
  font-family:"Georgia",serif;
  font-size:30px;
  letter-spacing:2px;
  color:var(--accent);
  text-shadow:0 1px 0 rgba(0,0,0,.5),0 0 14px rgba(196,167,71,.35);
}
.tagline{
  margin:4px 0 0;
  font-size:12px;
  letter-spacing:3px;
  text-transform:uppercase;
  color:#cfc6b2;
}

/* Pages */
.pages{
  flex:1;
  overflow-y:auto;
  background:
    radial-gradient(ellipse at 50% 0%,rgba(0,0,0,.04),transparent 60%),
    var(--secondary);
  -webkit-overflow-scrolling:touch;
}
.page{
  padding:20px 16px 90px;
  min-height:100%;
}
.section-title{
  font-size:14px;
  letter-spacing:2px;
  text-transform:uppercase;
  color:var(--primary);
  border-bottom:1px solid rgba(43,74,61,.25);
  padding-bottom:6px;
  margin:22px 0 12px;
}

/* Dashboard seals */
.seal-row{
  display:flex;
  justify-content:space-around;
  gap:14px;
  margin:6px 0 18px;
}
.seal{
  width:118px;
  height:118px;
  border-radius:50%;
  display:flex;
  align-items:center;
  justify-content:center;
  position:relative;
}
.seal::before{
  content:"";
  position:absolute;
  inset:6px;
  border-radius:50%;
  border:2px dashed rgba(255,255,255,.5);
}
.seal-ring{
  width:92px;
  height:92px;
  border-radius:50%;
  background:rgba(255,255,255,.10);
  border:2px solid rgba(255,255,255,.35);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  box-shadow:inset 0 2px 4px rgba(0,0,0,.3);
}
.seal.gold{
  background:radial-gradient(circle at 32% 28%,#e3c96b,#c4a747 55%,#9a7f2c);
  box-shadow:0 8px 16px rgba(0,0,0,.3), inset 0 1px 3px rgba(255,255,255,.5);
}
.seal.copper{
  background:radial-gradient(circle at 32% 28%,#c98a5a,#a4673a 55%,#7a4623);
  box-shadow:0 8px 16px rgba(0,0,0,.3), inset 0 1px 3px rgba(255,255,255,.4);
}
.seal-num{
  font-size:34px;
  font-weight:bold;
  line-height:1;
  color:rgba(255,255,255,.25);
  text-shadow:0 1px 1px rgba(255,255,255,.4),0 -1px 1px rgba(0,0,0,.6);
}
.seal-label{
  font-size:10px;
  letter-spacing:1px;
  text-transform:uppercase;
  color:rgba(255,255,255,.85);
  margin-bottom:2px;
}

/* Log button */
.log-btn{
  width:100%;
  padding:15px;
  font-family:"Georgia",serif;
  font-size:16px;
  letter-spacing:1px;
  color:#f7f0dc;
  background:var(--primary);
  border:none;
  border-radius:8px;
  box-shadow:inset 0 -3px 0 #1a2d24, 0 6px 12px rgba(0,0,0,.25);
}
.log-btn:active{transform:translateY(2px);box-shadow:inset 0 -1px 0 #1a2d24}

/* Mini gallery */
.mini-gallery{
  display:flex;
  gap:10px;
  overflow-x:auto;
  padding-bottom:8px;
  -webkit-overflow-scrolling:touch;
}
.mini-stub{
  flex:0 0 auto;
  width:120px;
  background:var(--paper);
  border-radius:6px;
  padding:8px;
  border-top:10px solid var(--accent);
  box-shadow:0 3px 8px rgba(0,0,0,.18);
}
.mini-stub .m-name{
  font-family:"Comic Sans MS","Segoe Script","Georgia",cursive;
  color:var(--indigo);
  font-size:12px;
  line-height:1.15;
  margin:0;
}
.mini-stub .m-date{
  font-size:9px;
  color:var(--faded-red);
  letter-spacing:1px;
  margin:4px 0 6px;
  font-family:"Courier New",monospace;
}
.mini-dots{display:flex;gap:3px}
.mini-dots .mdot{width:7px;height:7px;border-radius:50%;border:1px solid var(--accent-dark)}
.mini-dots .mdot.on{background:var(--accent-dark)}

/* Search */
.search-wrap{margin-bottom:14px}
.search{
  width:100%;
  padding:12px 14px;
  font-family:inherit;
  font-size:14px;
  border:1px solid rgba(43,74,61,.35);
  border-radius:8px;
  background:#fffdf7;
  box-shadow:inset 0 1px 3px rgba(0,0,0,.08);
}
.empty-note{
  text-align:center;
  color:#8a7f6d;
  font-style:italic;
  margin-top:30px;
}

/* Ticket stub cards */
.card-list{display:flex;flex-direction:column;gap:14px}
.stub{
  background:var(--paper);
  border-radius:8px;
  padding:14px 16px 14px 12px;
  position:relative;
  box-shadow:0 4px 12px rgba(0,0,0,.16);
  border-left:10px solid var(--accent);
  transition:box-shadow .15s ease,transform .15s ease;
  cursor:pointer;
}
.stub:active{transform:scale(.99)}
.stub.lifted{
  box-shadow:0 12px 26px rgba(0,0,0,.32);
  transform:translateY(-2px);
}
.stub::after{
  content:"";
  position:absolute;
  right:-10px;top:0;bottom:0;
  width:20px;
  background:
    radial-gradient(circle at 0 50%,transparent 6px,var(--paper) 7px);
  background-size:20px 20px;
  background-repeat:repeat-y;
  background-position:-2px 0;
}
.stub-top{display:flex;align-items:flex-start;justify-content:space-between;gap:10px}
.m-name{
  font-family:"Comic Sans MS","Segoe Script","Georgia",cursive;
  font-size:17px;
  line-height:1.2;
  color:var(--indigo);
  margin:0 0 4px;
  font-weight:bold;
}
.m-date{
  font-family:"Courier New",monospace;
  font-size:11px;
  color:var(--faded-red);
  letter-spacing:1px;
  text-transform:uppercase;
  opacity:.9;
}
.stub-foot{
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  margin-top:10px;
}
.dots{display:flex;gap:4px}
.dots .dot{width:12px;height:12px;border-radius:50%;border:1.5px solid var(--accent-dark)}
.dots .dot.on{background:var(--accent-dark)}
.icon{
  width:34px;height:34px;
  opacity:.7;
}
.m-impressions{
  font-size:13px;
  color:#5a4f3d;
  font-style:italic;
  margin:8px 0 0;
  line-height:1.4;
}

/* Inline row actions */
.row-actions{display:flex;gap:8px;flex:0 0 auto}
.row-btn{
  font-family:"Georgia",serif;
  font-size:11px;
  letter-spacing:1px;
  padding:6px 12px;
  border-radius:20px;
  border:1px solid rgba(43,74,61,.35);
  background:transparent;
  color:var(--primary);
}
.row-btn.del-btn{
  border-color:rgba(184,74,58,.5);
  color:var(--faded-red);
}
.row-btn.del-btn[data-armed="1"]{
  background:var(--faded-red);
  color:#fff;
}

/* Gallery grid */
.gallery-grid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:10px;
}
.gthumb{
  background:var(--paper);
  border-radius:8px;
  padding:8px;
  border-top:10px solid var(--accent);
  box-shadow:0 3px 8px rgba(0,0,0,.18);
  cursor:pointer;
  position:relative;
  aspect-ratio:3/4;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
}
.gthumb:active{transform:scale(.97)}
.gthumb .m-name{font-size:12px}
.gthumb .m-date{font-size:8px}
.gthumb .dots .dot{width:7px;height:7px}

/* Tab bar */
.tabbar{
  position:sticky;
  bottom:0;
  display:flex;
  background:linear-gradient(180deg,#b3963c,#c4a747);
  border-top:2px solid #9a7f2c;
  z-index:30;
  padding:0;
}
.tab{
  flex:1;
  border:none;
  background:linear-gradient(180deg,#c9b45e,#b3963c);
  color:#5c4b16;
  font-family:"Georgia",serif;
  font-size:12px;
  font-weight:bold;
  letter-spacing:.5px;
  padding:18px 4px calc(14px + env(safe-area-inset-bottom));
  position:relative;
  cursor:pointer;
  clip-path:polygon(6% 0,100% 0,100% 100%,0 100%,0 18%);
}
.tab-label{display:block}
.tab.active{
  background:linear-gradient(180deg,#f0e3b0,#dcc878 40%,#c9b45e);
  color:#4a3c10;
  transform:translateY(-4px);
  box-shadow:0 -3px 12px rgba(0,0,0,.35), 0 3px 6px rgba(255,255,255,.4);
  z-index:5;
}
.tab.active::before{
  content:"";
  position:absolute;
  top:6px;left:0;right:0;height:12px;
  background:linear-gradient(180deg,rgba(255,255,255,.7),rgba(255,255,255,0));
}

/* Forms */
.visit-form{display:flex;flex-direction:column;gap:16px}
.field{display:flex;flex-direction:column;gap:5px}
.field label{
  font-size:12px;
  letter-spacing:1px;
  text-transform:uppercase;
  color:var(--primary);
  font-weight:bold;
}
.visit-form input[type=text],
.visit-form input[type=date],
.visit-form textarea{
  padding:12px 14px;
  font-family:inherit;
  font-size:15px;
  border:1px solid rgba(43,74,61,.35);
  border-radius:8px;
  background:#fffdf7;
  box-shadow:inset 0 1px 3px rgba(0,0,0,.06);
}
.visit-form textarea{resize:vertical}
.visit-form input:focus,.visit-form textarea:focus{
  outline:none;
  border-color:var(--accent-dark);
  box-shadow:0 0 0 3px rgba(196,167,71,.25);
}
.err{color:#a33;font-size:12px;min-height:14px}

/* Star picker */
.star-picker{display:flex;gap:12px}
.star-picker .dot{
  width:30px;height:30px;border-radius:50%;
  border:2px solid var(--accent-dark);
  cursor:pointer;
  background:transparent;
  transition:background .1s;
}
.star-picker .dot.on{background:var(--accent-dark)}

/* Save seal button */
.save-seal{
  font-family:"Georgia",serif;
  font-size:16px;
  letter-spacing:1px;
  color:#f7f0dc;
  background:radial-gradient(circle at 32% 28%,#e3c96b,#c4a747 55%,#9a7f2c);
  border:2px solid #8a6e22;
  border-radius:40px;
  padding:15px;
  box-shadow:
    inset 0 -3px 6px rgba(0,0,0,.25),
    inset 0 2px 3px rgba(255,255,255,.5),
    0 6px 12px rgba(0,0,0,.25);
}
.save-seal:active{transform:translateY(2px)}
.save-seal.small{font-size:14px;padding:12px;flex:1}

/* Buttons */
.btn-row{display:flex;gap:10px;align-items:center}
.danger-btn{
  font-family:inherit;
  font-size:14px;
  padding:12px 16px;
  border-radius:8px;
  border:1px solid #a33;
  color:#a33;
  background:transparent;
  cursor:pointer;
}
.danger-btn.solid{background:#a33;color:#fff;border-color:#a33;flex:1}
.ghost-btn{
  font-family:inherit;
  font-size:14px;
  padding:12px 16px;
  border-radius:8px;
  border:1px solid rgba(43,74,61,.4);
  color:var(--primary);
  background:transparent;
  cursor:pointer;
  flex:1;
}
.form-err{text-align:center}

/* Overlay */
.overlay{
  position:absolute;
  inset:0;
  z-index:60;
  display:flex;
  align-items:flex-end;
  justify-content:center;
}
.overlay-scrim{
  position:absolute;
  inset:0;
  background:rgba(20,25,20,.55);
}
.overlay-sheet{
  position:relative;
  width:100%;
  max-width:520px;
  background:var(--secondary);
  border-radius:18px 18px 0 0;
  padding:20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height:86%;
  overflow-y:auto;
  box-shadow:0 -8px 30px rgba(0,0,0,.4);
}
.overlay-title{
  margin:0 0 16px;
  font-size:18px;
  color:var(--primary);
  letter-spacing:1px;
}
.confirm-sheet{text-align:center}
.confirm-text{color:#5a4f3d}

@media(min-width:560px){
  .overlay{top:0}
  .overlay-sheet{border-radius:18px;margin-bottom:20px}
}