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

body {
  font-family: Optima, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 15vw;
  flex-shrink: 0;
  padding: 20px;
  position: relative;
  overflow: hidden;
  background-color: var(--page-bg, #fff);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: var(--noise-color, transparent);
  -webkit-mask-image: linear-gradient(#fff, #fff), url('noise.png');
  mask-image: linear-gradient(#fff, #fff), url('noise.png');
  -webkit-mask-composite: source-out;
  mask-composite: exclude;
  -webkit-mask-mode: luminance;
  mask-mode: luminance;
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
  -webkit-mask-size: 100% 100%, 25% 25%;
  mask-size: 100% 100%, 25% 25%;
  pointer-events: none;
}

.sidebar::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 5px;
  background-color: var(--sidebar-border, rgba(128, 128, 128, .2));
  -webkit-mask-image: url('vert_border.svg');
  mask-image: url('vert_border.svg');
  -webkit-mask-repeat: repeat-y;
  mask-repeat: repeat-y;
  -webkit-mask-size: 5px auto;
  mask-size: 5px auto;
  pointer-events: none;
}

.sidebar > * {
  position: relative;
  z-index: 1;
}

.sidebar-img {
  display: block;
  max-width: 80%;
  height: auto;
}

.sidebar-caption {
  font-size: 14px;
  font-style: italic;
  margin-top: 12px;
  text-align: left;
  color: inherit;
  opacity: .7;
  align-self: flex-start;
  width: 100%;
}

.sidebar-para {
  font-size: 14px;
  line-height: 1.6;
  font-style: italic;
  margin-top: 32px;
  padding-left: 15px;
  padding-right: 15px;
  text-align: left;
  color: var(--sidebar-fg, inherit);
  opacity: .85;
  align-self: flex-start;
  width: 100%;
}

.sidebar-dropcap-wrap {
  float: left;
  width: 38px;
  margin: 2px 10px 4px 0;
}

.sidebar-dropcap {
  display: block;
  width: 38px;
  height: 38px;
  background-color: var(--sidebar-fg, currentColor);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: left top;
  mask-position: left top;
}

.sidebar-dropcap-wrap[data-cap="white"] .sidebar-dropcap {
  -webkit-mask-image: url('initial_cap_white.png');
  mask-image: url('initial_cap_white.png');
}

.sidebar-dropcap-wrap[data-cap="black"] .sidebar-dropcap {
  -webkit-mask-image: url('initial_cap_black.png');
  mask-image: url('initial_cap_black.png');
}

.sidebar-para-text {
}

.sidebar-para a {
  color: var(--sidebar-fg, inherit);
  opacity: .75;
  transition: opacity .2s;
}

.sidebar-para a:hover {
  opacity: 1;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 600px) {
  .app {
    flex-direction: column;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 100%;
    order: 2;
    padding: 24px 20px;
    align-items: center;
  }
  .sidebar-img {
    order: 2;
    max-width: 60%;
  }
  .sidebar-para {
    order: 1;
    margin-top: 0;
    padding-bottom: 15px;
    align-self: stretch;
    text-align: left;
  }
  .main {
    order: 1;
  }
}

/* ── Tabs (desktop) ── */
.tabs {
  display: flex;
  align-items: center;
  background: var(--page-bg, rgba(128, 128, 128, .2));
  position: sticky;
  top: 0;
  z-index: 1000;
  overflow-x: auto;
}

.tabs::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: var(--noise-color, transparent);
  -webkit-mask-image: linear-gradient(#fff, #fff), url('noise.png');
  mask-image: linear-gradient(#fff, #fff), url('noise.png');
  -webkit-mask-composite: source-out;
  mask-composite: exclude;
  -webkit-mask-mode: luminance;
  mask-mode: luminance;
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
  -webkit-mask-size: 100% 100%, 25% 25%;
  mask-size: 100% 100%, 25% 25%;
  pointer-events: none;
}

.tabs > * {
  position: relative;
  z-index: 1;
}

.border-deco-desktop {
  height: 20px;
  margin-top: -10px;
  position: sticky;
  top: 30px;
  z-index: 999;
  background-color: var(--nav-color, rgba(128, 128, 128, .3));
  -webkit-mask-image: url('border.svg');
  mask-image: url('border.svg');
  -webkit-mask-repeat: repeat-x;
  mask-repeat: repeat-x;
  -webkit-mask-size: auto 100%;
  mask-size: auto 100%;
}

.tab {
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
  opacity: .55;
  position: relative;
  transition: opacity .2s;
  font-size: 14px;
  letter-spacing: .02em;
  white-space: nowrap;
}

.tab:hover {
  opacity: .8;
}

.tab.active {
  opacity: 1;
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background-color: var(--tab-active-border, currentColor);
  -webkit-mask-image: url('underline.svg');
  mask-image: url('underline.svg');
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center bottom;
  mask-position: center bottom;
}

.tab-sep {
  display: inline-block;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  background-color: var(--sep-color, rgba(128, 128, 128, .25));
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  vertical-align: middle;
  opacity: .5;
}

/* ── Site link ── */
.site-link {
  position: fixed;
  top: 0;
  right: 0;
  padding: 12px 20px 12px 20px;
  z-index: 1001;
  font-size: 14px;
  letter-spacing: .02em;
  color: inherit;
  text-decoration: none;
  opacity: .6;
  transition: opacity .2s;
}

.site-link:hover {
  opacity: 1;
}

/* ── Mobile ── */
.map-select {
  display: none;
}

.border-deco-mobile {
  display: none;
}

@media (max-width: 600px) {
  .tabs {
    display: none;
  }

  .border-deco-desktop {
    display: none;
  }

  .map-select {
    display: block;
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    padding: 20px 16px;
    background: var(--page-bg, rgba(128, 128, 128, .25));
  }
  .map-select::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background-color: var(--noise-color, transparent);
    -webkit-mask-image: linear-gradient(#fff, #fff), url('noise.png');
    mask-image: linear-gradient(#fff, #fff), url('noise.png');
    -webkit-mask-composite: source-out;
    mask-composite: exclude;
    -webkit-mask-mode: luminance;
    mask-mode: luminance;
    -webkit-mask-repeat: repeat;
    mask-repeat: repeat;
    -webkit-mask-size: 100% 100%, 25% 25%;
    mask-size: 100% 100%, 25% 25%;
    pointer-events: none;
  }
  .border-deco-mobile {
    display: block;
    height: 20px;
    margin-top: -10px;
    position: relative;
    z-index: 999;
    background-color: var(--nav-color, rgba(128, 128, 128, .3));
    -webkit-mask-image: url('border.svg');
    mask-image: url('border.svg');
    -webkit-mask-repeat: repeat-x;
    mask-repeat: repeat-x;
    -webkit-mask-size: auto 100%;
    mask-size: auto 100%;
  }

  .map-select select {
    position: relative;
    z-index: 1;
    width: 100%;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    letter-spacing: .02em;
    background: rgba(128, 128, 128, .15);
    color: inherit;
    border: 1px solid rgba(128, 128, 128, .3);
    border-radius: 6px;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
  }

  .site-link {
    order: 3;
    position: static;
    display: block;
    text-align: center;
    padding: 24px 16px;
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    opacity: .5;
    z-index: auto;
  }

  .content {
    width: 100%;
    margin: 0 auto;
    padding: 20px 16px;
    text-align: left;
    display: flex;
    flex-direction: column;
  }
  .content #viewers {
    order: 2;
  }
  .content .right-col {
    order: 1;
    width: 100%;
    padding-left: 0;
    padding-top: 0;
    padding-bottom: 16px;
  }
  .content .desc {
    text-align: left;
    max-width: 100%;
  }
}

/* ── Content ── */
.content {
  width: 90%;
  margin: 0 auto;
  padding: 20px 0;
  position: relative;
  z-index: 1;
}

@media (min-width: 601px) {
  .content {
    --content-gap: 30px;
    margin: 0 var(--content-gap) var(--content-gap) var(--content-gap);
    width: auto;
    padding-bottom: 0;
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
  }
  .content #viewers {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .content .right-col {
    width: 15vw;
    flex-shrink: 0;
    padding-left: 24px;
  }
  .content .viewer-wrap {
    margin-bottom: 0;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .content .viewer-wrap .osd-viewer {
    flex: 1;
    min-height: 400px;
    height: auto;
  }
  body.grid-mode .content .viewer-wrap .osd-viewer {
    flex: none;
    height: 45vh;
    min-height: 260px;
  }
}

.desc {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
  max-width: 65ch;
  position: relative;
  z-index: 2;
}

.desc a {
  color: inherit;
  opacity: .85;
  text-decoration: underline;
}

.desc a:hover {
  opacity: 1;
}

#dlwrap {
  margin-bottom: 24px;
}

.dl {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-bottom: 4px;
  color: inherit;
  opacity: .75;
  position: relative;
  z-index: 2;
  text-decoration: underline;
}

.dl:hover {
  opacity: 1;
}

.backlit-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: .03em;
  color: #fff;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 4px;
  cursor: pointer;
  opacity: .4;
  transition: opacity .2s, background .2s;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  pointer-events: auto;
}

.backlit-btn:hover {
  opacity: .75;
}

.backlit-btn.active {
  opacity: .9;
  background: rgba(0, 0, 0, .5);
}

.backlit-btn.active .backlit-icon {
  -webkit-mask-image: url('backlit_mode_on.svg');
  mask-image: url('backlit_mode_on.svg');
}

.backlit-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: url('backlit_mode.svg');
  mask-image: url('backlit_mode.svg');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.dl-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: url('download_icon.svg');
  mask-image: url('download_icon.svg');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.buy-icon,
.buy-backlit-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask-image: url('buy_icon_2.svg');
  mask-image: url('buy_icon_2.svg');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.buy-backlit-icon {
  -webkit-mask-image: url('buy_icon_1.svg');
  mask-image: url('buy_icon_1.svg');
}

/* ── Viewer ── */
.viewer-wrap {
  position: relative;
  overflow: visible;
  margin-bottom: 32px;
}

.viewer-pattern {
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  z-index: 0;
  pointer-events: none;
  border-radius: 8px;
  background-color: var(--oc, rgba(128, 128, 128, .3));
  -webkit-mask-image: url('bg_pattern.svg');
  mask-image: url('bg_pattern.svg');
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
  -webkit-mask-size: 72px auto;
  mask-size: 72px auto;
}

/* ── Corner ornaments ── */
.viewer-ornament {
  position: absolute;
  pointer-events: none;
  z-index: 1;
  background-color: var(--oc, rgba(128, 128, 128, .3));
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-mode: alpha;
  mask-mode: alpha;
}

.ornament-top-left {
  width: 44px; height: 48px;
  top: -24px; left: -22px;
  -webkit-mask-image: url('top_left_ornament.svg');
  mask-image: url('top_left_ornament.svg');
}

.ornament-top-right {
  width: 42px; height: 48px;
  top: -24px; right: -21px;
  -webkit-mask-image: url('top_right_ornament.svg');
  mask-image: url('top_right_ornament.svg');
}

.ornament-bottom-left {
  width: 67px; height: 69px;
  bottom: -35px; left: -34px;
  -webkit-mask-image: url('bottom_left_ornament.svg');
  mask-image: url('bottom_left_ornament.svg');
}

.ornament-bottom-right {
  width: 40px; height: 32px;
  bottom: -16px; right: -20px;
  -webkit-mask-image: url('bottom_right_ornament.svg');
  mask-image: url('bottom_right_ornament.svg');
}

/* ── Border frame (9-slice from WHOLE.svg) ── */
.viewer-border {
  position: absolute;
  inset: -4px;
  pointer-events: none;
  z-index: 2;
}

.viewer-border > div {
  position: absolute;
  background-color: var(--oc, rgba(128, 128, 128, .3));
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-mode: alpha;
  mask-mode: alpha;
}

/* Corners — fixed size */
.border-corner { width: 20px; height: 20px; }
.border-corner-top-left     { top: 0; left: 0;   -webkit-mask-image: url('b-tl.svg'); mask-image: url('b-tl.svg'); }
.border-corner-top-right    { top: 0; right: 0;  -webkit-mask-image: url('b-tr.svg'); mask-image: url('b-tr.svg'); }
.border-corner-bottom-left  { bottom: 0; left: 0;  -webkit-mask-image: url('b-bl.svg'); mask-image: url('b-bl.svg'); }
.border-corner-bottom-right { bottom: 0; right: 0; -webkit-mask-image: url('b-br.svg'); mask-image: url('b-br.svg'); }

/* Horizontal edges — stretch between corners, fixed height */
.border-edge-horizontal {
  left: 20px;
  right: 20px;
  height: 20px;
}
.border-edge-top    { top: 0;    -webkit-mask-image: url('b-top.svg'); mask-image: url('b-top.svg'); }
.border-edge-bottom { bottom: 0; -webkit-mask-image: url('b-bottom.svg'); mask-image: url('b-bottom.svg'); }

/* Vertical edges — stretch between corners, fixed width */
.border-edge-vertical {
  top: 20px;
  bottom: 20px;
  width: 20px;
}
.border-edge-left  { left: 0;  -webkit-mask-image: url('b-left.svg'); mask-image: url('b-left.svg'); }
.border-edge-right { right: 0; -webkit-mask-image: url('b-right.svg'); mask-image: url('b-right.svg'); }

.osd-viewer {
  width: 100%;
  height: 70vh;
  min-height: 400px;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.zoom-ctrl {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: auto;
}

.zoom-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  opacity: .25;
  transition: opacity .2s;
  padding: 2px 6px;
  font-family: system-ui, sans-serif;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  -webkit-user-select: none;
  user-select: none;
}

.zoom-btn:hover {
  opacity: .55;
}

.viewer-label {
  font-size: 14px;
  letter-spacing: .04em;
  text-transform: uppercase;
  opacity: .5;
  margin: 32px 0 10px;
  position: relative;
  z-index: 1;
}

.viewer-label:first-of-type {
  margin-top: 0;
}

/* ── One-page grid ── */
body.grid-mode #viewers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
  align-items: start;
}

.grid-card {
  position: relative;
}

.grid-card-title {
  font-size: 14px;
  letter-spacing: .03em;
  font-weight: 600;
  margin-top: 16px;
  margin-bottom: 6px;
  position: relative;
  z-index: 2;
}

.grid-card-desc {
  font-size: 14px;
  line-height: 1.5;
  opacity: .7;
  margin-bottom: 8px;
  position: relative;
  z-index: 2;
}

.grid-card-desc a {
  color: inherit;
  opacity: .85;
  text-decoration: underline;
}

.grid-card-desc a:hover {
  opacity: 1;
}

.grid-card-dlrow {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 0;
  position: relative;
  z-index: 2;
}

.grid-card-dlrow .dl {
  display: inline-flex;
  margin-bottom: 0;
}

body.grid-mode .osd-viewer {
  height: 45vh;
  min-height: 260px;
}

body.grid-mode .desc {
  display: none;
}

body.grid-mode #dlwrap {
  display: none;
}

body.grid-mode .right-col {
  display: none;
}

body.grid-mode .grid-card-title {
  display: none;
}

body.grid-mode .viewer-wrap {
  margin-bottom: 12px;
}

.grid-intro {
  display: none;
}

@media (max-width: 600px) {
  body.grid-mode #viewers {
    grid-template-columns: 1fr;
  }

  body.grid-mode .osd-viewer {
    height: 70vh;
    min-height: 400px;
  }

  body.grid-mode .sidebar {
    display: none;
  }

  body.grid-mode .grid-intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 16px 16px;
  }

  body.grid-mode .grid-intro-img {
    max-width: 50%;
    height: auto;
    display: block;
    margin-bottom: 16px;
  }

  body.grid-mode .grid-intro .sidebar-para {
    font-size: 14px;
    line-height: 1.6;
    font-style: italic;
    text-align: left;
    opacity: .85;
    width: 100%;
    padding: 0;
    margin: 0;
  }
}

#errlog {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 150px;
  overflow-y: auto;
  background: rgba(200, 0, 0, .92);
  color: #fff;
  font: 12px/1.4 monospace;
  padding: 8px;
  display: none;
  z-index: 9999;
}

#errlog.on {
  display: block;
}
