:root {
  --primary: #f7f3e8;
  --secondary: #6b8e56;
  --accent: #d94f30;
  --ink: #2e2a24;
  --ink-soft: #6d6355;
  --wood-dark: #6b4a2b;
  --wood: #a97b4f;
  --wood-light: #c49a67;
  --shadow: 0 6px 16px rgba(60, 42, 20, 0.18);
}

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

html, body { height: 100%; }

body {
  font-family: "Georgia", "Times New Roman", serif;
  color: var(--ink);
  background: var(--wood);
  overscroll-behavior: none;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  background: var(--wood);
  position: relative;
  overflow: hidden;
}

/* ---- Bamboo mat background ---- */
#screens {
  flex: 1;
  position: relative;
  overflow-y: auto;
  background:
    linear-gradient(90deg, rgba(120, 86, 48, 0.12) 0 1px, transparent 1px),
    repeating-linear-gradient(0deg, var(--wood-light) 0, var(--wood) 9px, var(--wood-light) 10px);
  background-size: 100% 100%, auto;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  scroll-behavior: smooth;
}

.mat-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.04) 0 2px, transparent 2px 26px),
    linear-gradient(160deg, rgba(255,255,255,0.10) 0%, rgba(0,0,0,0.05) 60%);
  opacity: 0.6;
  z-index: 0;
}

.screen { position: relative; z-index: 1; }

/* ---- Top bar ---- */
.topbar {
  background: linear-gradient(180deg, var(--wood-dark), var(--wood));
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 12px;
  box-shadow: 0 2px 0 rgba(0,0,0,0.15);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-crane {
  width: 30px; height: 30px;
  background: var(--primary);
  clip-path: polygon(50% 0, 62% 38%, 100% 24%, 72% 52%, 88% 100%, 50% 68%, 12% 100%, 28% 52%, 0 24%, 38% 38%);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}
.brand h1 { font-size: 22px; letter-spacing: 2px; color: var(--primary); }
.brand .tagline { font-size: 10px; color: rgba(247,243,232,0.75); letter-spacing: 1px; }

/* ---- Dashboard ---- */
.dash { display: flex; flex-direction: column; gap: 18px; padding-top: 16px; }

.crane-card {
  position: relative;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 16px;
}
.crane-white .crane { background: #fbf7ec; }
.crane-pattern .crane {
  background:
    repeating-linear-gradient(45deg, rgba(107,142,86,0.35) 0 6px, rgba(247,243,232,0.25) 6px 12px),
    #e8ddc2;
}

/* folded crane */
.crane {
  position: relative;
  width: 64px; height: 64px;
  flex: 0 0 64px;
  border-radius: 4px;
  box-shadow: var(--shadow);
  transform: rotate(-6deg);
  clip-path: polygon(50% 2%, 100% 28%, 66% 56%, 90% 100%, 50% 72%, 8% 100%, 30% 56%, 0 28%);
}
.crane .wing { position: absolute; width: 50%; height: 60%; top: 24%; transform-origin: 50% 0; }
.crane .wing-back { left: 0; background: rgba(0,0,0,0.08); transform: rotate(-14deg); border-radius: 6px; }
.crane .wing-front { right: 0; background: rgba(0,0,0,0.14); transform: rotate(14deg); border-radius: 6px; }
.crane .head { position: absolute; left: 62%; top: -6%; width: 12px; height: 16px; background: inherit; transform: rotate(28deg); border-radius: 0 0 4px 4px; }
.crane .tail { position: absolute; right: 66%; bottom: -4%; width: 10px; height: 18px; background: inherit; transform: rotate(-24deg); border-radius: 4px 0 0 4px; }

.crane-tally { display: flex; flex-direction: column; gap: 4px; }
.tally-label { font-size: 12px; letter-spacing: 1px; color: rgba(46,42,36,0.7); }
.tally-num {
  font-size: 46px;
  font-weight: 700;
  color: #2a2a2a;
  font-family: "Georgia", serif;
  text-shadow: 1px 1px 0 rgba(247,243,232,0.5);
  line-height: 1;
}

/* New Model button */
.new-model-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: linear-gradient(180deg, var(--secondary), #5b7a47);
  color: var(--primary);
  border: none;
  border-radius: 6px;
  padding: 14px;
  font-size: 16px;
  font-family: "Georgia", serif;
  letter-spacing: 1px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.square-fold {
  width: 22px; height: 22px; display: inline-block;
  background: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
  transform: rotate(45deg) scale(0.9);
  position: relative;
}
.square-fold::after { content: ""; position: absolute; left: 50%; top: 0; width: 1px; height: 100%; background: rgba(0,0,0,0.2); transform: translateX(-50%); }

/* Recent */
.recent-title { font-size: 14px; letter-spacing: 1px; color: var(--ink-soft); margin-bottom: 10px; text-transform: uppercase; }
.recent-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.recent-item {
  background: var(--primary);
  border-radius: 4px;
  padding: 10px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--accent);
  text-align: center;
}
.recent-item .sq { width: 34px; height: 34px; margin: 0 auto 6px; transform: rotate(45deg); background: var(--primary); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); border-right: 3px solid var(--secondary); border-bottom: 3px solid var(--accent); }
.recent-item .name { font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .date { font-size: 9px; color: var(--ink-soft); }

/* ---- Screen titles ---- */
.screen-title { font-size: 18px; letter-spacing: 1px; margin: 6px 0 14px; color: var(--wood-dark); }

/* ---- Log ---- */
.search-box input {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 6px;
  background: rgba(247,243,232,0.85);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
  font-family: "Georgia", serif;
  font-size: 14px;
  margin-bottom: 14px;
}
.log-list { display: flex; flex-direction: column; gap: 14px; }
.log-card {
  background: var(--primary);
  border-radius: 4px;
  padding: 14px 16px 30px;
  box-shadow: var(--shadow);
  position: relative;
  cursor: pointer;
}
.log-card::before { /* faint centre crease */
  content: "";
  position: absolute;
  left: 50%; top: 6px; bottom: 6px;
  width: 1px;
  background: rgba(0,0,0,0.08);
  transform: translateX(-50%);
}
.log-card .model-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.log-card .meta { font-size: 12px; color: var(--ink-soft); display: flex; gap: 10px; flex-wrap: wrap; }
.log-card .notes { font-size: 12px; color: var(--ink-soft); margin-top: 6px; font-style: italic; }
.hanko { /* red seal */
  position: absolute; right: 12px; bottom: 8px;
  width: 34px; height: 34px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 9px;
  display: flex; align-items: center; justify-content: center;
  transform: rotate(-8deg);
  text-align: center;
  line-height: 1;
}
.diff-pill { padding: 1px 8px; border-radius: 12px; font-size: 11px; color: var(--primary); }
.diff-easy { background: #8fb573; }
.diff-medium { background: #c99b3f; }
.diff-hard { background: var(--accent); }

.empty { text-align: center; color: var(--ink-soft); padding: 30px 0; font-style: italic; }

/* ---- Form ---- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 6px;
  background: rgba(247,243,232,0.9);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
  font-family: "Georgia", serif;
  font-size: 15px;
}
.field textarea { resize: vertical; }
.field .error { color: var(--accent); font-size: 12px; margin-top: 4px; display: block; min-height: 14px; }
.submit-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--accent), #c4432a);
  color: var(--primary);
  font-family: "Georgia", serif;
  font-size: 16px;
  letter-spacing: 1px;
  box-shadow: var(--shadow);
  cursor: pointer;
  margin-top: 4px;
}
.form-hint { text-align: center; font-size: 11px; color: var(--ink-soft); margin-top: 10px; font-style: italic; }

/* ---- Tips ---- */
.tips { display: flex; flex-direction: column; gap: 12px; }
.tip-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--primary);
  border-radius: 4px;
  padding: 14px;
  box-shadow: var(--shadow);
  border-left: 3px solid var(--secondary);
}
.tip-num {
  flex: 0 0 28px; height: 28px;
  background: var(--secondary);
  color: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.tip-card p { font-size: 13px; line-height: 1.5; }
.tip-card strong { color: var(--wood-dark); }

/* ---- Bottom tab bar ---- */
.tabbar {
  display: flex;
  background: linear-gradient(180deg, var(--wood), var(--wood-dark));
  box-shadow: 0 -2px 0 rgba(0,0,0,0.18);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
}
.tab {
  flex: 1;
  border: none;
  background: var(--wood);
  border-radius: 4px 4px 0 0;
  margin: 0 2px;
  padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: rgba(46,42,36,0.65);
  font-family: "Georgia", serif;
  font-size: 11px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  position: relative;
}
.tab .tab-icon {
  width: 20px; height: 20px; display: block;
  background: currentColor;
  opacity: 0.8;
}
.i-home { clip-path: polygon(50% 0, 100% 45%, 80% 45%, 80% 100%, 20% 100%, 20% 45%, 0 45%); }
.i-log { clip-path: polygon(0 0, 100% 0, 100% 20%, 75% 20%, 75% 100%, 50% 100%, 50% 20%, 25% 20%, 25% 100%, 0 100%); }
.i-new { clip-path: polygon(25% 0, 25% 25%, 0 25%, 0 75%, 25% 75%, 25% 100%, 75% 100%, 75% 75%, 100% 75%, 100% 25%, 75% 25%, 75% 0); }
.i-tips { clip-path: polygon(50% 0, 100% 25%, 75% 100%, 25% 100%, 0 25%); }

.tab.active {
  background: var(--wood-light);
  color: var(--ink);
  transform: translateY(-4px);
  box-shadow: 0 -3px 8px rgba(60,42,20,0.25);
  position: relative;
}
.tab.active::after { /* green-dyed tip */
  content: "";
  position: absolute;
  top: -2px; left: 50%;
  transform: translateX(-50%);
  width: 60%; height: 4px;
  background: var(--secondary);
  border-radius: 0 0 2px 2px;
}

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(40,28,12,0.5); }
.modal-sheet {
  position: relative;
  width: 100%; max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--wood);
  border-radius: 12px 12px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -6px 20px rgba(0,0,0,0.3);
}
.modal-sheet h3 { font-size: 18px; margin-bottom: 16px; color: var(--wood-dark); }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.modal-actions .spacer { flex: 1; }
.btn-delete, .btn-cancel, .btn-save {
  border: none; border-radius: 6px; padding: 12px 16px;
  font-family: "Georgia", serif; font-size: 14px; cursor: pointer;
}
.btn-delete { background: var(--accent); color: var(--primary); }
.btn-cancel { background: rgba(247,243,232,0.7); color: var(--ink-soft); }
.btn-save { background: linear-gradient(180deg, var(--secondary), #5b7a47); color: var(--primary); }

@media (min-width: 480px) {
  #app { border-left: 1px solid rgba(0,0,0,0.15); border-right: 1px solid rgba(0,0,0,0.15); }
  .modal { align-items: center; padding-bottom: 0; }
  .modal-sheet { border-radius: 12px; }
}