:root {
  color-scheme: light;
  font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172a3a;
  background: #eaf1f7;
  --ink: #172a3a;
  --muted: #5d7081;
  --paper: #fff;
  --line: #d7e1e9;
  --blue: #176397;
  --blue-dark: #123e60;
  --blue-pale: #e9f2f8;
  --shadow: 0 5px 16px rgb(20 49 73 / 5%);
}
* { box-sizing: border-box; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(180deg, #eaf1f7 0, #f2f6fa 24rem);
}
main { width: min(100% - 2rem, 46rem); margin: 0 auto; padding: clamp(1rem, 2.4vw, 1.6rem) 0 3rem; }
header, footer, .header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
h1, h2 { margin: 0; line-height: 1.15; }
h1 { font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: clamp(2.2rem, 7vw, 3.25rem); font-weight: 750; letter-spacing: -.045em; }
h2 { letter-spacing: -.015em; }
button, input, textarea, select { font: inherit; }
button {
  min-height: 44px;
  padding: .62rem 1rem;
  border: 1px solid transparent;
  border-radius: 0;
  color: white;
  background: var(--blue-dark);
  box-shadow: 0 2px 6px rgb(36 35 31 / 10%);
  cursor: pointer;
  transition: background-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
button:hover:not(:disabled) { background: #0c3451; box-shadow: 0 5px 13px rgb(20 49 73 / 12%); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: .58; cursor: default; }
.secondary { color: var(--blue-dark); background: #fff; border-color: #bacbd8; box-shadow: none; }
.secondary:hover:not(:disabled) { color: #102f48; background: #edf4f9; }
.icon-button { display: grid; width: 44px; height: 44px; flex: 0 0 44px; place-items: center; padding: .5rem; }
.icon-button svg { width: 1.35rem; height: 1.35rem; fill: currentColor; }
.danger { background: #873e34; }
.danger:hover:not(:disabled) { background: #713129; }
:focus-visible { outline: 3px solid #3789bb; outline-offset: 3px; }
#price-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1.4rem 0 1.75rem;
  padding: 1.2rem 1.35rem;
  border: 1px solid #5b523e;
  border-radius: 0;
  color: #f7fbff;
  background: linear-gradient(125deg, #123550, #1d5b82);
  box-shadow: 0 10px 24px rgb(20 49 73 / 13%);
}
#price-panel h2 { color: #d6e8f5; font-size: .96rem; font-weight: 650; }
#price-panel p { margin: .25rem 0 0; }
#gold-price { color: #fff; font-size: clamp(1.35rem, 4vw, 1.8rem); font-weight: 700; letter-spacing: -.025em; }
#price-time, #price-fetch-time, #price-status { color: #d9e8f2; font-size: .88rem; }
#collection-value { margin-top: .85rem !important; padding-top: .7rem; border-top: 1px solid rgb(255 255 255 / 23%); color: #fff; font-weight: 650; }
#refresh-price { color: var(--blue-dark); background: #fff; box-shadow: none; }
#refresh-price:hover:not(:disabled) { background: #eaf3f9; }
#status {
  margin: 0 0 1rem;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--muted);
  background: var(--paper);
}
#coin-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(10rem, .45fr);
  gap: .75rem;
  margin: 0 0 .45rem;
}
#coin-filters[hidden], #coin-count[hidden], #filter-empty[hidden] { display: none; }
#coin-filters label { min-width: 0; }
#coin-count { margin: 0 0 .6rem; color: var(--muted); font-size: .86rem; }
#filter-empty { margin: 0 0 .75rem; padding: .8rem 1rem; border: 1px solid var(--line); background: var(--paper); color: var(--muted); }
ul { display: grid; gap: .8rem; margin: 0; padding: 0; list-style: none; }
li {
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--paper);
  box-shadow: var(--shadow);
  transition: border-color .16s ease, box-shadow .16s ease;
}
li:hover { border-color: #a7c3d6; box-shadow: 0 8px 22px rgb(20 49 73 / 8%); }
summary { position: relative; padding: .25rem 0 .25rem 1.7rem; cursor: pointer; overflow-wrap: anywhere; font-weight: 620; list-style: none; }
summary::marker { content: ""; }
summary::-webkit-details-marker { display: none; }
summary::before {
  position: absolute;
  top: .18rem;
  left: 0;
  display: grid;
  width: 1.2rem;
  height: 1.2rem;
  place-items: center;
  border-radius: 0;
  color: var(--blue-dark);
  background: var(--blue-pale);
  content: "+";
  font-size: .95rem;
  line-height: 1;
}
details[open] > summary::before { content: "−"; }
.coin-summary { display: grid; grid-template-columns: minmax(0, 1fr) max-content; align-items: center; gap: .75rem; }
.coin-summary-main { min-width: 0; }
.coin-name { display: block; overflow-wrap: anywhere; font-size: 1.04rem; font-weight: 700; }
.coin-subtitle { display: block; margin: .18rem 0 0; color: var(--muted); font-size: .88rem; font-weight: 450; }
.coin-summary-values { display: grid; gap: .12rem; text-align: right; font-size: .86rem; }
.coin-summary-value { display: flex; justify-content: flex-end; align-items: baseline; gap: .45rem; white-space: nowrap; }
.coin-summary-value-label { color: var(--muted); font-size: .74rem; font-weight: 450; }
.coin-summary-value-amount { font-variant-numeric: tabular-nums; }
dl { display: grid; grid-template-columns: minmax(9rem, auto) 1fr; gap: .3rem .8rem; margin: .9rem 0 0; padding-top: .85rem; border-top: 1px solid #eee9df; }
dt { color: var(--muted); font-size: .9rem; }
dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.coin-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .9rem; }
#backup-panel {
  margin-top: 1rem;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgb(255 254 250 / 75%);
}
#backup-panel > summary { color: #344f65; font-weight: 650; }
#tools-dialog { width: min(100% - 2rem, 34rem); }
.tools-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.tools-dialog-head h2 { font-size: 1.25rem; }
#csv-panel { margin-top: .8rem; padding: .75rem .9rem; border: 1px solid var(--line); background: #fff; }
#csv-panel > summary { color: #344f65; font-weight: 650; }
#csv-panel p, #backup-status { color: var(--muted); }
.print-action { margin: 1rem 0; }
#print-list { display: flex; width: 100%; min-height: 54px; align-items: center; justify-content: center; gap: .65rem; color: white; background: var(--blue); font-size: 1.03rem; font-weight: 650; }
#print-list:hover:not(:disabled) { background: #0e4e78; }
#print-list svg { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
dialog {
  width: min(100% - 2rem, 38rem);
  max-height: 90dvh;
  padding: 1.4rem;
  border: 1px solid var(--line);
  border-radius: 0;
  color: inherit;
  background: var(--paper);
  box-shadow: 0 24px 70px rgb(20 18 12 / 25%);
}
dialog::backdrop { background: rgb(20 39 55 / 48%); backdrop-filter: blur(3px); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; margin: 1.2rem 0; }
.wide { grid-column: 1 / -1; }
label { color: #344f65; font-size: .92rem; font-weight: 570; }
input, textarea, select {
  display: block;
  width: 100%;
  min-height: 46px;
  margin-top: .28rem;
  padding: .55rem .65rem;
  border: 1px solid #d5cdbf;
  border-radius: 0;
  color: var(--ink);
  background: #fff;
}
#csv-file[hidden] { display: none !important; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); outline: 3px solid rgb(55 137 187 / 20%); }
textarea { resize: vertical; }
select { margin-bottom: 1rem; }
footer { justify-content: flex-end; }
#form-error, #restore-error { color: #8b3328; }
#backup-panel { padding: .75rem .9rem; background: #fff; }
#backup-status { margin-bottom: .75rem; font-size: .9rem; }
#app-version { display: block; margin-top: 2rem; padding: .8rem 0 .25rem; border-top: 1px solid var(--line); color: #71859a; font-size: .75rem; text-align: center; }
#scroll-top {
  position: fixed;
  z-index: 20;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: grid;
  width: 3rem;
  height: 3rem;
  place-items: center;
  padding: 0;
  color: #fff;
  background: var(--blue-dark);
  box-shadow: 0 6px 18px rgb(20 49 73 / 20%);
}
#scroll-top[hidden] { display: none !important; }
#scroll-top:hover:not(:disabled) { background: var(--blue); transform: translateY(-2px); }
#scroll-top svg { width: 1.4rem; height: 1.4rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter; }
@media (max-width: 34rem) {
  main { width: min(100% - 1.25rem, 46rem); margin: 0 auto; padding: max(.75rem, env(safe-area-inset-top)) 0 2rem; }
  header { align-items: flex-start; }
  .header-actions { width: 100%; }
  #add { width: auto; flex: 1 1 auto; }
  #tools-open { width: 48px; flex-basis: 48px; }
  #price-panel { align-items: flex-start; padding: 1rem; }
  #refresh-price { width: 100%; }
  #coin-filters { grid-template-columns: 1fr; gap: .45rem; }
  .coin-summary { gap: .45rem; }
  .coin-summary-value { gap: .3rem; }
  .coin-summary-value-label { font-size: .68rem; }
  dl { grid-template-columns: 1fr; gap: .05rem; }
  dd { margin: 0 0 .5rem; }
  .fields { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
@media print {
  :root { background: white; color: black; font-size: 11pt; }
  body { min-width: 0; margin: 0; background: white; }
  main { width: auto; margin: 0; }
  .header-actions, #refresh-price, #price-status, #tools-dialog, .coin-actions, #app-version, #scroll-top { display: none !important; }
  #price-panel { display: block; margin: .75rem 0; padding: 0; border: 0; border-radius: 0; color: black; background: white; box-shadow: none; }
  #price-panel h2, #gold-price, #price-time, #price-fetch-time, #collection-value { color: black; }
  #collection-value { border-top: 1px solid #aaa; }
  #status:empty, #status[hidden] { display: none !important; }
  ul { display: block; margin: 1rem 0 0; }
  #coins > li { break-inside: avoid; margin: 0 0 .75rem; padding: .5rem 0; border: 0; border-bottom: 1px solid #999; border-radius: 0; background: white; box-shadow: none; }
  #coins details:not([open]) > :not(summary) { display: block !important; }
  #coins summary { font-weight: 700; }
  #coins summary::before { display: none; }
  #coins .coin-subtitle { margin-left: 0; }
  dl { display: grid; grid-template-columns: max-content 1fr; column-gap: .75rem; border-color: #ddd; }
  dt, dd { margin: 0; }
  dialog { display: none !important; }
}
