@layer site, tools, overrides;
@import url("/style.css") layer(site);

@layer tools {
  .calc-page {
    padding-block-start: clamp(24px, 4vw, 40px);
  }
  .calc-page > .container { container-type: inline-size; }
  .calc-head h1 { font-size: clamp(2rem, 4.6vw, 3rem); }
  .calc-only { margin-block-start: 8px; color: var(--muted); font-weight: 700; }
  .calc-classes {
    margin-block-start: 20px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
    gap: 4px 18px;
    & .party { display: flex; flex-direction: column; gap: 2px; }
    & a {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 3px 6px;
      border-radius: 8px;
      white-space: nowrap;
      min-block-size: 36px;
      color: var(--on-dark);
      text-decoration: none;
      font-weight: 700;
      font-size: 1rem;
      line-height: 1.25;
      &:hover { color: var(--on-dark-link); background: rgba(0, 0, 0, .18); }
      &[aria-current="page"] { color: var(--on-dark-link); background: rgba(0, 0, 0, .28); }
      & img, & .init { width: 22px; height: 22px; border-radius: 50%; flex: none; image-rendering: auto; }
      & .init { display: grid; place-items: center; background: var(--ball-2); color: var(--ball-ink); font-size: .7rem; }
    }
  }
  .calc-help { margin-block-start: 16px; font-size: .95rem; color: var(--muted); max-width: 880px; }
  .calc-total {
    margin-block-start: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px 24px;
    flex-wrap: wrap;
    font-size: .98rem;
  }
  .calc-level {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    & label { margin-inline-end: 4px; }
    & input {
      width: 4.2em;
      height: 36px;
      text-align: center;
      font: 800 1rem var(--font-body);
      color: var(--text);
      border: 1px solid var(--line-strong);
      border-radius: var(--radius-sm);
      background: var(--bg-1);
    }
  }
  .calc-step {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    background: var(--bg-3);
    cursor: pointer;
    font: 800 1.1rem/1 var(--font-body);
    color: var(--on-dark);
    &:hover { background: #2c5820; }
  }
  .calc-link {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    font-weight: 700;
    color: var(--orange-ink);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    &:hover { color: var(--green-ink); }
  }
  .calc-notice {
    margin-block-start: 8px;
    padding-block: 8px; padding-inline: 12px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    font-weight: 700;
    color: var(--green-ink);
    &.bad { color: var(--danger); border-color: rgba(255, 90, 95, .45); }
  }
  .calc-panels {
    --cw: 86px;
    --ch: 64px;
    margin-block-start: 12px;
    display: grid;
    grid-template-columns: repeat(2, max-content);
    gap: 24px clamp(24px, 6vw, 96px);
    justify-content: center;
    align-items: start;
  }
  @container (width < 936px) {
    .calc-panels { grid-template-columns: max-content; justify-content: center; }
  }
  @container (width < 468px) {
    .calc-panels { --cw: calc((100cqw - 20px) / 5); --ch: calc(var(--cw) * .74); }
  }
  .calc-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
  .calc-panel { width: calc(var(--cw) * 5 + 20px); }
  .calc-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    background: linear-gradient(180deg, #2a4a0c 0%, #1d3a00 100%);
    color: #fff;
    box-shadow: 0 0 0 1px #0f2405, inset 0 1px 0 rgba(255, 255, 255, .15);
    & h2 { font: 400 1.05rem/1.2 var(--font-display); letter-spacing: .03em; color: #fff; flex: 1; min-width: 0; }
    & .sp { font-weight: 800; white-space: nowrap; font-size: .95rem; }
    & .calc-link { color: var(--on-dark-link); }
    & .ball {
      width: 18px;
      height: 18px;
      border-radius: 50%;
      flex: none;
      background: radial-gradient(circle at 34% 28%, var(--ball-hi) 0 10%, var(--ball-1) 25%, var(--ball-2) 60%, var(--ball-3) 100%);
    }
  }
  .calc-body {
    margin-block-start: 8px;
    padding: 10px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line-strong);
  }
  .calc-tree {
    position: relative;
    width: calc(var(--cw) * 5);
    & svg.lines { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; overflow: visible; pointer-events: none; }
  }
  .lines path {
    fill: none;
    stroke: rgba(255, 255, 255, .28);
    stroke-width: 4;
    stroke-linejoin: round;
    &.tip { fill: rgba(255, 255, 255, .28); stroke: none; }
  }
  .lines .on path {
    stroke: #ffd25a;
    &.tip { fill: #ffd25a; stroke: none; }
  }
  .skill {
    --bg1: #8e9a86;
    --bg2: #4d5847;
    position: absolute;
    width: calc(var(--cw) - 14px);
    height: calc(var(--ch) - 12px);
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    background: linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
    border: 2px solid rgba(0, 0, 0, .55);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 2px 0 rgba(0, 0, 0, .35);
    display: flex;
    align-items: center;
    gap: 4px;
    padding-block: 0;
    padding-inline: 6px 4px;
    filter: saturate(.35) brightness(.62);
    transition: filter .12s var(--ease), transform .08s var(--ease);
    &:focus-visible { outline: 3px solid var(--ball-1); outline-offset: 2px; }
    &.can { filter: saturate(.75) brightness(.9); border-color: #ffd25a; box-shadow: 0 0 0 2px rgba(255, 210, 90, .35), 0 2px 0 rgba(0, 0, 0, .35); }
    &.learned {
      filter: none;
      border-color: #fff;
      box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 0 10px rgba(255, 230, 140, .35), 0 2px 0 rgba(0, 0, 0, .35);
    }
    &.fixed { cursor: default; }
    &:active { transform: translateY(1px); }
  }
  .skill--physical { --bg1: #e0453b; --bg2: #7d1410; }
  .skill--energy { --bg1: #4b8fe0; --bg2: #143f86; }
  .skill--blessing { --bg1: #4fbf3a; --bg2: #1c5e10; }
  .skill--curse { --bg1: #9a5ad6; --bg2: #43176e; }
  .skill--passive { --bg1: #c4cbd2; --bg2: #5d6670; }
  .skill--htb { --bg1: #f59a2a; --bg2: #9a3d00; }
  .skill--mastery { --bg1: #f1d04a; --bg2: #8f6a00; }
  .skill--other { --bg1: #f07a2a; --bg2: #8a2f00; }
  .skill__icon {
    width: calc(var(--ch) - 24px);
    height: calc(var(--ch) - 24px);
    max-width: 40px;
    max-height: 40px;
    flex: none;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(0, 0, 0, .35);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .6);
    display: grid;
    place-items: center;
    color: #fff;
    font: 800 .8rem/1 var(--font-body);
    & img { width: 100%; height: 100%; display: block; image-rendering: auto; }
  }
  .skill__num {
    margin-inline-start: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    font: 800 .95rem/1.05 var(--font-body);
    color: #fff;
    text-shadow: 0 1px 0 #000, 0 0 3px #000;
    & b { font-weight: 800; }
    & i { font-style: normal; opacity: .85; border-block-start: 1px solid rgba(255, 255, 255, .55); padding-block-start: 1px; min-width: 1.1em; text-align: center; }
  }
  @container (width < 468px) {
    .skill { gap: 2px; padding-block: 0; padding-inline: 3px 2px; border-radius: 6px; }
    .skill__num { font-size: .78rem; }
  }
  .calc-share {
    width: calc(var(--cw) * 5 + 20px);
    max-width: 100%;
    & .btn { width: 100%; }
    & p { margin-block-start: 8px; font-size: .85rem; color: var(--muted); }
  }
  .calc-card {
    position: fixed;
    z-index: 60;
    max-width: min(340px, calc(100vw - 16px));
    padding: 10px 12px;
    background: rgba(255, 255, 255, .96);
    color: var(--text);
    border: 1px solid var(--frame-edge);
    border-radius: 8px;
    box-shadow: 0 10px 28px -10px rgba(0, 0, 0, .45);
    font-size: .86rem;
    line-height: 1.35;
    pointer-events: none;
    backdrop-filter: blur(4px);
    & h3 { font: 800 1rem/1.25 var(--font-body); color: #111; }
    & .g { color: var(--muted); font-weight: 700; font-size: .82rem; }
    & .fx { margin-block-start: 2px; }
    & .gap { height: .7em; }
    & .ok { color: var(--ok); }
    & .bad { color: var(--danger); font-weight: 700; }
    & .desc { margin-block-start: 6px; color: var(--muted); font-size: .82rem; }
    & .next { margin-block-start: 8px; padding-block-start: 6px; border-block-start: 1px solid var(--frame-edge); }
    & .next h4 { font: 800 .84rem/1.3 var(--font-body); color: var(--green-ink); }
    & .actions { display: none; }
    @media (hover: none) {
      inset-inline: 8px;
      inset-block: auto 8px;
      max-width: none;
      pointer-events: auto;
      max-block-size: 60dvh;
      overflow: auto;
      padding-block-end: 12px;
      & .actions { display: flex; gap: 10px; margin-block-start: 10px; position: sticky; inset-block-end: -12px; padding-block: 8px; background: #fff; }
      & .actions button {
        flex: 1;
        min-height: 44px;
        border-radius: 999px;
        border: 1px solid var(--line-strong);
        background: #fff;
        color: var(--text);
        font: 800 1.2rem var(--font-body);
        cursor: pointer;
      }
      & .actions .close { flex: 1.4; font-size: .95rem; }
    }
  }
  .calc-loading, .calc-error { padding-block: 24px; color: var(--muted); font-weight: 700; }
  .calc-error { color: var(--danger); }
}

@layer overrides {
  .calc-page [hidden] { display: none; }
}
