:root {
  --bg: #fff;
  --panel: #ffffff;
  --ink: #6d5b59;
  --muted: #6d5b59;
  --node-fill: #ffffff;
  --node-border: #6d7481;
  --hex-border: #ffffff;
}

@font-face {
  font-family: "Inter";
  src: url("/fonts/Inter-Variable-Subset-Latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Arsenica Arabic Antiqua";
  src: url("./assets/Arsenica-Arabic-Antiqua-Demibold-TRIAL.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #fefefe 0%, var(--bg) 70%);
  overflow: hidden;
  position:relative;
}

.app {
  min-height: 100vh;
  position: relative;
}

.panel {
  background: #fff2f1;
  border-right: 0;
  padding: 20px;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 240px;
  font-family: "Inter", "Avenir Next", "Segoe UI", sans-serif;
  border-radius: 0 24px 24px 0;
  box-shadow: 0 -4px 14px rgba(62, 47, 46, 0.2);
  z-index: 30;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 48px;
  justify-content: center;
}

.panel-header-block {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel-header-block[hidden] {
  display: none !important;
}

h1 {
  margin: 0;
  font-size: 54px;
  font-family: "Arsenica Arabic Antiqua", "Avenir Next", "Segoe UI", sans-serif;
  font-weight: 600;
  color: #6f5d5b;
  line-height: 0.75;
  letter-spacing: -0.015em;
}

.menu-toggle,
.app-drawer,
.drawer-backdrop {
  display: none;
}

.sheet-toggle {
  display: none;
}

h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

p {
  margin-top: 0;
  line-height: 1.4;
  color: var(--muted);
}

.share-tools {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.share-tools button {
  width: auto;
  border: 0;
  background: #ffffff;
  color: #6d5b59;
  border-radius: 24px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.share-tools button:hover {
  background: #f5d9d6;
}

.share-tools .secondary-action {
  background: #f9e3e1;
  padding: 6px 12px;

}

.share-tools .secondary-action:hover {
  background: #f5d9d6;


}

.share-tools p {
  margin: 0 2px;
  font-size: 12px;
  min-height: 1.1em;
}

.editor {
  margin: 18px 0 24px;
  padding: 14px;
  border-radius: 12px;
  background: #f8f9fc;
  border: 1px solid #e3e6ee;
}

.editor.floating-editor {
  position: fixed;
  z-index: 120;
  width: 210px;
  margin: 0;
  background: rgba(248, 249, 252, 0.97);
  border: 1px solid #cfd6e4;
  box-shadow: 0 8px 18px rgba(23, 31, 45, 0.16);
  transform: translate(-50%, calc(-100% + 8px)) scale(0.98);
  opacity: 0;
  transition:
    transform 180ms cubic-bezier(0.2, 0.9, 0.25, 1),
    opacity 150ms ease;
}

.editor.floating-editor.is-open {
  transform: translate(-50%, -100%) scale(1);
  opacity: 1;
}

.editor-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: #e9edf6;
  color: #6d5b59;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.editor-close:hover {
  background: #dde4f2;
}

.editor.floating-editor h2 {
  padding-right: 28px;
}

.editor.floating-editor h2 {
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.editor.floating-editor label {
  margin-top: 8px;
  font-size: 0.85rem;
}

.editor-groups {
  display: block;
}

.editor-group {
  display: block;
}

label {
  display: block;
  margin: 10px 0 4px;
  font-size: 0.92rem;
}

select {
  width: 100%;
  border: 1px solid #cdd3e1;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  font-size: 0.95rem;
}

@media (min-width: 1101px) and (hover: hover) {
  .editor select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m3 6 5 5 5-5' fill='none' stroke='%236d5b59' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
  }
}

.dice-table ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
}

.dice-table {
  display: none;
}

.dice-table li {
  font-size: 0.9rem;
  color: #6d5b59;
}

.selection-summary {
  margin-top: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.selection-summary[hidden] {
  display: none !important;
}

.selection-summary ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.selection-summary li {
  margin: 0;
  font-size: 12px;
  color: #6d5b59;
  border-radius: 999px;
  background: #ffffff;
  padding: 4px 8px;
  line-height: 1;
  font-weight: 700;
  white-space: nowrap;
}

.selection-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  font-family: "Inter", "Avenir Next", "Segoe UI", sans-serif;
  font-weight: 700;
  color: #6d5b59;
}

.selection-meta {
  margin: 0;
  display: grid;
  align-items: start;
  gap: 0;
  font-size: 12px;
  line-height: 1.5;
  color: #6d5b59;
  font-weight: 500;
}

.selection-meta span {
  display: block;
}

.selection-meta strong {
  font-weight: 700;
}

.selection-summary-header {
  display: grid;
  gap: 4px;
}

#deselectNodesBtn {
  margin-top: 0;
  border: 0;
  background: #f9e3e1;
  color: #6d5b59;
  border-radius: 24px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1;
  justify-self: flex-start;
}

#deselectNodesBtn:hover {
  background: #f5d9d6;
}

.deselect-icon {
  font-size: 12px;
  line-height: 1;
}

.sheet-intro {
  margin: 0;
  color: #6d5b59;
  font-family: "Inter", "Avenir Next", "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}

.board-wrap {
  position: fixed;
  left: 240px;
  right: 0;
  top: 0;
  bottom: 0;
  overflow: hidden;
  padding: 0;
  background: #ffffff;
  z-index: 1;
  cursor: grab;
  touch-action: none;
}

.board-wrap.is-panning {
  cursor: grabbing;
}

.zoom-controls {
  display: none;
}

.map-stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.map-stage .hex,
.map-stage .hex-number,
.map-stage .node {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.ephemeral-prompt {
  position: fixed;
  left: calc(50vw + 120px);
  top: 50vh;
  transform: translate(-50%, -50%);
  z-index: 9999;
  isolation: isolate;
  background: #fff2f1;
  color: #6d5b59;
  border-radius: 16px;
  box-shadow: 0 -4px 14px rgba(62, 47, 46, 0.2);
  padding: 14px 18px;
  font-family: "Inter", "Avenir Next", "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  min-width: 220px;
  max-width: min(90vw, 420px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.ephemeral-prompt.is-visible {
  opacity: 1;
}

.board {
  position: relative;
  min-width: 320px;
  min-height: 320px;
  --render-scale: 1;
}

.hex {
  position: absolute;
  width: var(--hex-size);
  height: calc(var(--hex-size) * 1.1547);
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 120ms ease;
  z-index: 1;
  background: transparent;
  outline: none;
}

.hex:focus,
.hex:focus-visible,
.hex:active {
  outline: none;
  box-shadow: none;
}

.hex:hover {
  transform: translate(-50%, -50%) scale(1.01) !important;
}

.hex.selected {
  z-index: 2;
  outline: none;
  transform: translate(-50%, -50%) scale(1.02) !important;
}

.hex-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.hex-number {
  font-family: "Inter", sans-serif;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(34px * var(--render-scale));
  height: calc(34px * var(--render-scale));
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #ffffff;
  font-weight: 700;
  font-size: calc(19px * var(--render-scale));
  color: #17191f;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  z-index: 3;
  pointer-events: none;
}

.hex.slot {
  position: absolute;
  border: 0;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.hex.slot::before {
  content: "";
  position: absolute;
  inset: 2px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  pointer-events: none;
}

.node {
  position: absolute;
  width: calc(10px * var(--render-scale));
  height: calc(10px * var(--render-scale));
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--node-prob-color, #cfd8e8);
  border: 0;
  color: transparent;
  font-weight: 400;
  font-size: 0;
  transform: translate(-50%, -50%) scale(0.9);
  pointer-events: auto;
  cursor: pointer;
  z-index: 20;
  transition:
    transform 220ms cubic-bezier(0.22, 1.35, 0.35, 1),
    width 140ms ease,
    height 140ms ease,
    background-color 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.node.selected {
  width: calc(36px * var(--render-scale));
  height: calc(36px * var(--render-scale));
  background: var(--node-prob-color, #6d7481);
  border: calc(2px * var(--render-scale)) solid var(--node-prob-color, #6d7481);
  color: #3e4b64;
  font-size: calc(10px * var(--render-scale));
  box-shadow: 0 0 0 2px rgb(255 255 255), 4px 6px 16px 0 rgba(31,33,42,.25);
  transform: translate(-50%, -50%) scale(1);
}

@media (max-width: 1100px), (hover: none) and (pointer: coarse) {
  .menu-toggle,
  .drawer-close {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #fff2f1;
    color: #6d5b59;
    cursor: pointer;
  }

  .menu-toggle {
    position: fixed;
    left: calc(16px + env(safe-area-inset-left));
    top: calc(16px + env(safe-area-inset-top));
    z-index: 70;
    box-shadow: 0 3px 12px rgb(62 47 46 / 18%);
  }

  .drawer-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 80;
    border: 0;
    background: rgb(35 28 27 / 30%);
  }

  .app-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 90;
    width: 85%;
    max-width: 420px;
    padding: calc(20px + env(safe-area-inset-top)) 24px calc(36px + env(safe-area-inset-bottom));
    background: #fff2f1;
    border-radius: 0 24px 24px 0;
    overflow-y: auto;
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform 220ms ease, visibility 220ms;
  }

  .app-drawer.is-open {
    visibility: visible;
    transform: translateX(0);
    box-shadow: 8px 0 28px rgb(62 47 46 / 18%);
  }

  .drawer-close {
    align-self: flex-end;
    flex-shrink: 0;
    background: #f9e3e1;
    font-size: 28px;
    margin-bottom: 32px;
  }

  .app-drawer .panel-header-block {
    gap: 24px;
  }

  .app-drawer .sheet-intro {
    font-size: 16px;
    line-height: 1.5;
  }

  .app-drawer .share-tools {
    align-items: stretch;
  }

  .app-drawer .share-tools button {
    min-height: 44px;
  }

  .panel.mobile-idle {
    display: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .app-drawer { transition: none; }
  }

  body {
    overflow: hidden;
  }

  .app {
    display: block;
    min-height: 100dvh;
  }

  .panel {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: auto;
    min-width: 0;
    z-index: 60;
    border-right: 0;
    border-top: 1px solid #f0dcda;
    border-radius: 18px 18px 0 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    max-height: 56dvh;
    overflow: auto;
    background: #fff2f1;
    backdrop-filter: blur(8px);
    box-shadow: 0 -8px 24px rgba(20, 30, 45, 0.14);
    transition: max-height 180ms ease, padding 180ms ease;
    gap: 0;
  }

  .ephemeral-prompt {
    left: 50vw;
  }

  .panel-header-block {
    gap: 8px;
  }

  .sheet-toggle {
    display: grid;
    place-items: center;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 4px 0 8px;
    margin: 0;
    cursor: pointer;
  }

  .sheet-grip {
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: #6D5B59;
  }

  .panel.mobile-collapsed {
    max-height: calc(28px + env(safe-area-inset-bottom));
    padding-top: 6px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .panel.mobile-collapsed > :not(.sheet-toggle) {
    display: none;
  }

  .panel.mobile-summary .sheet-intro,
  .panel.mobile-summary .share-tools {
    display: none;
  }

  .panel:not(.mobile-summary) .selection-summary {
    display: none;
  }

  .panel.mobile-summary .selection-summary {
    display: grid;
    gap:12px;
    margin-top: 6px;
    border: 0;
    background: transparent;
    border-radius: 0;
    padding: 0;
  }
  .panel.mobile-summary .selection-summary-header {
    display: grid;
    gap:4px;
  }

  .panel.mobile-editing .sheet-intro,
  .panel.mobile-editing .share-tools,
  .panel.mobile-editing .selection-summary {
    display: none;
  }

  .panel h1 {
    display: block;
    margin: 4px 0 8px;
    font-size: clamp(52px, 13.2vw, 64px);
    line-height: 0.78;
    letter-spacing: -0.015em;
    color: #6d5b59;
  }

  .panel.mobile-summary h1,
  .panel.mobile-editing h1 {
    display: none;
  }

  .sheet-intro {
    margin: 0;
    color: #6d5b59;
    font-family: "Inter", "Avenir Next", "Segoe UI", sans-serif;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
  }

  .share-tools {
    margin: 6px 0 4px;
  }

  .share-tools button {
    width: auto;
    min-width: 142px;
    border: 0;
    background: #f9e3e1;
    color: #6d5b59;
    border-radius: 24px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
  }

  .share-tools p {
    margin: 8px 2px 0;
    font-size: 12px;
  }

  .panel.mobile-editing .editor {
    display: block;
    margin: 2px 0 0;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .panel.mobile-editing .editor h2 {
    display: block;
    margin: 0 0 8px;
    font-family: "Inter", "Avenir Next", "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    font-weight: 700;
    color: #6d5b59;
  }

  .panel.mobile-editing .editor .editor-close {
    display: none;
  }

  .panel.mobile-editing .editor-groups {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px 12px;
    flex-wrap: wrap;
  }

  .panel.mobile-editing .editor-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
  }

  .panel.mobile-editing .editor-group-number {
    margin-left: auto;
  }

  .panel.mobile-editing .editor label {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    color: #6d5b59;
    font-weight: 500;
  }

  .panel.mobile-editing .editor select {
    width: auto;
    min-width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: #f9e3e1;
    color: #6d5b59;
    font-size: 16px;
    font-weight: 500;
    padding: 0 16px;
    appearance: none;
    -webkit-appearance: none;
    background-image: none;
    line-height: 1.2;
  }

  .panel.mobile-editing .editor #tileNumber {
    width: 44px;
    padding: 0;
    text-align: center;
    text-align-last: center;
  }

  .panel.mobile-editing {
    max-height: min(56dvh, calc(220px + env(safe-area-inset-bottom)));
    padding-top: 10px;
    padding-bottom: calc(36px + env(safe-area-inset-bottom));
    overflow: auto;
  }

  .board-wrap {
    position: fixed;
    inset: 0;
    display: block;
    overflow: hidden;
    padding: 0;
    touch-action: none;
    background: #ffffff;
    z-index: 1;
    cursor: default;
  }

  .zoom-controls {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 16px);
    right: 16px;
    z-index: 40;
    display: flex;
    gap: 8px;
    filter: drop-shadow(1px 1px 4px rgba(62, 47, 46, 0.2));
    pointer-events: auto;
  }

  .zoom-btn {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #6d5b59;
    display: grid;
    place-items: center;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    font-weight: 500;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    pointer-events: auto;
  }

  .zoom-btn-face {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: #fff2f1;
    display: grid;
    place-items: center;
    color: #6d5b59;
    font-size: 18px;
    line-height: 1;
    font-weight: 500;
    pointer-events: none;
  }

.zoom-btn:active {
  transform: translateY(1px);
}

  .map-stage {
    position: absolute;
    left: 0;
    top: 0;
    will-change: transform;
  }

  .board {
    width: auto;
    max-width: none;
    margin: 0 auto;
    transform: none;
  }
}
