*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:          #ffffff;
  --bg2:         #f5f5f3;
  --bg3:         #eeede8;
  --border:      rgba(0,0,0,0.12);
  --border2:     rgba(0,0,0,0.22);
  --text:        #1a1a18;
  --text2:       #5f5e5a;
  --text3:       #9c9a92;
  --blue-bg:     #e6f1fb;
  --blue:        #185fa5;
  --blue-dark:   #0c447c;
  --purple-bg:   #eeedfe;
  --purple:      #534ab7;
  --green-bg:    #eaf3de;
  --green:       #3b6d11;
  --red-bg:      #fcebeb;
  --red:         #a32d2d;
  --amber-bg:    #faeeda;
  --amber:       #854f0b;
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #252523;
    --bg2:        #000000;
    --bg3:       #2e2e2b;
    --border:    rgba(255,255,255,0.10);
    --border2:   rgba(255,255,255,0.20);
    --text:      #e8e6de;
    --text2:     #9c9a92;
    --text3:     #666460;
    --blue-bg:   #0c2540;
    --blue:      #85b7eb;
    --blue-dark: #b5d4f4;
    --purple-bg: #1e1a40;
    --purple:    #afa9ec;
    --green-bg:  #162610;
    --green:     #97c459;
    --red-bg:    #2a1010;
    --red:       #f09595;
    --amber-bg:  #2a1e08;
    --amber:     #ef9f27;
  }
}

/* ── Layout ── */

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg2);
  min-height: 100vh;
  padding: 24px 16px 48px;
}

.page {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

a {
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.page-sub {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 8px;
}

/* ── Sections ── */

.section {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 14px;
}

.field {
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.flabel {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.req {
  color: var(--red);
  font-size: 10px;
}

.hint {
  font-size: 11px;
  color: var(--text3);
  margin-top: 5px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* ── Form controls ── */

select,
input[type="text"],
input[type="date"],
textarea {
  width: 100%;
  font-size: 13px;
  font-family: inherit;
  padding: 7px 10px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  transition: border-color 0.12s;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%239c9a92' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--blue);
}

select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Level cards ── */

.lcard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lcard {
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  user-select: none;
}

.lcard:hover {
  background: var(--bg2);
}

.lcard.sel {
  border: 2px solid var(--blue);
  background: var(--blue-bg);
}

.lcard-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 3px;
}

.lcard-sub {
  font-size: 11px;
  color: var(--text2);
}

.lcard.sel .lcard-sub {
  color: var(--blue-dark);
}

/* ── Level blocks ── */

.lvl-block {
  border: 0.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}

.lvl-block:last-child {
  margin-bottom: 0;
}

.lvl-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg2);
  border-bottom: 0.5px solid var(--border);
}

.lvl-head-label {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.lvl-count {
  font-size: 12px;
  color: var(--text2);
}

.lvl-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}

.lb1 { background: var(--blue-bg);   color: var(--blue-dark); }
.lb2 { background: var(--purple-bg); color: var(--purple); }

.lvl-body {
  padding: 12px 14px;
}

/* ── Tag pills ── */

.pills-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
  min-height: 4px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 0.5px solid var(--border2);
}

.pill-manual {
  background: var(--bg2);
  color: var(--text);
}

.pill-inherited {
  background: var(--bg3);
  color: var(--text2);
  border-color: var(--border);
}

.pill-excluded {
  background: var(--bg3);
  color: var(--text3);
  border: 0.5px dashed var(--border2);
  text-decoration: line-through;
}

.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pill-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 2px;
}

.pt-inherited { background: var(--bg3);   color: var(--text3); }
.pt-excluded  { background: var(--red-bg); color: var(--red); }

.pill-x {
  cursor: pointer;
  color: var(--text3);
  font-size: 15px;
  line-height: 1;
  margin-left: 2px;
  background: none;
  border: none;
  font-family: inherit;
  padding: 0;
}

.pill-x:hover { color: var(--red); }

.pill-undo {
  cursor: pointer;
  font-size: 11px;
  color: var(--blue);
  margin-left: 4px;
  background: none;
  border: none;
  font-family: inherit;
  padding: 0;
  text-decoration: underline;
  white-space: nowrap;
}

/* ── Tag group dropdown ── */

.tag-dropdown {
  width: 100%;
  font-size: 13px;
  font-family: inherit;
  padding: 7px 28px 7px 10px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  margin-bottom: 8px;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%239c9a92' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.tag-dropdown:focus {
  border-color: var(--blue);
}

/* ── Asset preview ── */

.asset-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg2);
  border-radius: var(--radius-md);
}

.ap-count {
  font-size: 20px;
  font-weight: 500;
  color: var(--blue);
  min-width: 20px;
}

.ap-label {
  color: var(--text2);
  font-size: 12px;
  flex: 1;
}

.ap-names {
  font-size: 11px;
  color: var(--text3);
  text-align: right;
}

/* ── Inheritance divider ── */

.inheritance-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text3);
  padding: 2px 0 8px;
}

.in-line {
  flex: 1;
  height: 0.5px;
  background: var(--border);
}

/* ── Summary ── */

.sum-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.sum-card {
  background: var(--bg2);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.sum-val {
  font-size: 22px;
  font-weight: 500;
}

.sum-lbl {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
}

.c-blue   { color: var(--blue); }
.c-purple { color: var(--purple); }
.c-amber  { color: var(--amber); }

/* ── Save bar ── */

.save-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  gap: 12px;
}

.sb-label {
  font-size: 12px;
  color: var(--text2);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-name {
  font-weight: 500;
  color: var(--text);
}

.save-btn {
  padding: 7px 20px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.1s;
}

.save-btn:hover    { opacity: 0.88; }
.save-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.save-btn.saved    { background: var(--green); }

/* ── Misc ── */

.no-tag-note {
  font-size: 11px;
  color: var(--text3);
}
