@import "totem";

.system-vermine2047 .vermine2047.actor {

  // ── Fix contrast: dark text on light parchment bg ───────────────────
  .window-content,
  & {
    color: @theme-color-dark;

    label, span, p, li, a:not(.active) {
      color: @theme-color-dark;
    }

    h4, h5 {
      color: @color-text-dark-header;
    }

    h3 {
      color: @theme-color-light;
    }

    input:not([type="radio"]):not([type="checkbox"]),
    select, textarea {
      color: #333;
      line-height: 1.2;
      padding: 1px 4px;
    }

    .char-header {
      h1 label {
        font-size: 0.9rem;
      }
      .char-name-value {
        font-size: 1.1rem;
      }
      input:not([type="radio"]):not([type="checkbox"]) {
        font-size: 1rem;
      }
    }

    .ability input.hexa {
      font-size: 0.8rem;
    }

    .resource-label {
      color: @color-text-dark-secondary;
    }

    .ability label {
      color: @color-text-dark-header;
    }

    .char-header {
      color: @theme-color-dark;

      label {
        color: @color-text-dark-header;
      }
    }

    .hexa {
      color: @color-text-dark-primary;
    }

    .sheet-tabs a {
      color: @color-text-dark-inactive;
      &.active {
        color: @theme-color-dark;
      }
    }
  }

  // ── Two-column layout for character sheets ──────────────────────────
  &.character {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 1fr auto !important;

    > header.window-header {
      grid-column: 1;
      grid-row: 1;
    }

    > section.window-content {
      grid-column: 1;
      grid-row: 2;
    }

    > div.window-resize-handle {
      grid-column: 1;
      grid-row: 3;
    }
  }

  &.character .window-content {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr;
    overflow: hidden;

    > .tab.main {
      grid-column: 1;
      grid-row: 1 / -1;
      display: flex !important;
      flex-direction: column;
      overflow-y: auto;
      padding: 8px;
      border-right: 1px solid rgba(255, 255, 255, 0.1);

      > * {
        flex: 0 0 auto;
      }
    }

    > nav.tabs {
      grid-column: 2;
      grid-row: 1;
    }

    > .tab:not(.main) {
      grid-column: 2;
      grid-row: 2;
      display: none;
      overflow-y: auto;
      padding: 8px;

      &.active {
        display: flex;
        flex-direction: column;
      }
    }
  }

  // ── Stacked layout for NPC sheets (header + tabs + content) ────────
  &.npc {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: auto 1fr auto !important;

    > header.window-header {
      grid-column: 1;
      grid-row: 1;
    }

    > section.window-content {
      grid-column: 1;
      grid-row: 2;
    }

    > div.window-resize-handle {
      grid-column: 1;
      grid-row: 3;
    }
  }

  &.npc .window-content {
    display: grid;
    grid-template-rows: auto auto 1fr;
    grid-template-columns: 1fr;
    overflow: hidden;

    > .tab.main {
      grid-column: 1;
      grid-row: 1;
      display: flex !important;
      flex-direction: column;
      overflow-y: auto;
      padding: 8px;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    }

    > nav.tabs {
      grid-column: 1;
      grid-row: 2;
    }

    > .tab:not(.main) {
      grid-column: 1;
      grid-row: 3;
      display: none;
      overflow-y: auto;
      padding: 8px;

      &.active {
        display: flex;
        flex-direction: column;
      }
    }
  }

  // ── Stacked layout for creature sheets (header + tabs + content) ───
  &.creature .window-content {
    display: grid;
    grid-template-rows: auto auto 1fr;
    grid-template-columns: 1fr;
    overflow: hidden;

    > .tab.main {
      grid-column: 1;
      grid-row: 1;
      display: flex !important;
      flex-direction: column;
      overflow-y: auto;
      padding: 8px;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    }

    > nav.tabs {
      grid-column: 1;
      grid-row: 2;
    }

    > .tab:not(.main) {
      grid-column: 1;
      grid-row: 3;
      display: none;
      overflow-y: auto;
      padding: 8px;

      &.active {
        display: flex;
        flex-direction: column;
      }
    }
  }

  form {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;

    > .tab {
      flex: 1;
      overflow-y: auto;
      padding: 4px;
    }

    .charname input {
      color: @theme-color-dark;
      font-family: "DistressBlack", sans-serif;
      font-size: 30px;
      font-style: normal;
    }

    div.hexa {
      .hexa-style();
      .transition();
      margin: 0.2rem;
      position: relative;

      &:hover {
        .hexa-style(rgba(255, 255, 255, 0.425), rgba(0, 0, 0, 0.288));
      }

      input {
        position: absolute;
        width: 100%;
        height: 100%;
        opacity: 0;
        z-index: 1;
        margin: 0;
        cursor: pointer;
      }

      &.checked {
        .hexa-style(rgb(0, 0, 0), rgba(0, 0, 0, 0.288));
        &:hover { .hexa-style(rgb(43, 43, 43), rgba(0, 0, 0, 0.288)); }
      }

    &.unavailable {
      background: radial-gradient(circle, rgba(66, 15, 15, 0.664) 0%, rgba(131, 70, 70, 0.432) 100%);
      pointer-events: none;
    }
    }

    input[type="text"],
    input[type="number"] {
      width: calc(100% - 2px);
      height: calc(100% - 2px);
      background: none;
      padding: 0;
      margin: 1px 0;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0);

      &.hexa { .hexa-style(); }
    }

    input[disabled],
    select[disabled] {
      cursor: not-allowed;
    }

    input[type="text"]:hover:not(:disabled),
    input[type="text"]:focus,
    select:hover:not(:disabled),
    select:focus,
    input[type="number"]:hover:not(:disabled),
    input[type="number"]:focus,
    textarea:hover:not(:disabled),
    textarea:focus {
      box-shadow: 0 0 10px @theme-color-highlight inset;
    }

    select {
      font-size: 0.6rem;
      border: none;
      appearance: none;
      min-width: fit-content;
      max-width: fit-content;
      padding: 0 0.2rem;
      margin: 0 0.2rem;
      cursor: help;
    }

    label {
      display: block;
    }

    .mce-panel span {
      display: inherit;
    }

    .rollable:hover,
    a:hover {
      color: #000;
      text-shadow: 0 5px 5px @theme-color-accent;
      cursor: pointer;
    }

    .chooseTotem {
      font-family: "DistressBlack", sans-serif;
      font-size: 0.8rem;
      cursor: pointer;

      &:hover {
        text-shadow: 0 0 10px @theme-color-highlight;
      }
    }
  }

  // Fiche personnage (ApplicationV2 : l'élément fiche EST le <form>, le
  // sélecteur "form div.hexa" ci-dessus ne s'y applique donc pas).
  &.character div.hexa {
    .hexa-style();
    .transition();
    margin: 0.2rem;
    position: relative;

    &:hover {
      .hexa-style(rgba(255, 255, 255, 0.425), rgba(0, 0, 0, 0.288));
    }

    input {
      position: absolute;
      width: 100%;
      height: 100%;
      opacity: 0;
      z-index: 1;
      margin: 0;
      cursor: pointer;
    }

    &.checked {
      .hexa-style(rgb(0, 0, 0), rgba(0, 0, 0, 0.288));
      &:hover { .hexa-style(rgb(43, 43, 43), rgba(0, 0, 0, 0.288)); }
    }
  }

  // Fiche de Groupe : mêmes dés de Réserve cliquables (AppV2).
  &.group div.hexa {
    .hexa-style();
    .transition();
    margin: 0.2rem;
    position: relative;

    &:hover {
      .hexa-style(rgba(255, 255, 255, 0.425), rgba(0, 0, 0, 0.288));
    }

    input {
      position: absolute;
      width: 100%;
      height: 100%;
      opacity: 0;
      z-index: 1;
      margin: 0;
      cursor: pointer;
    }

    &.checked {
      .hexa-style(rgb(0, 0, 0), rgba(0, 0, 0, 0.288));
      &:hover { .hexa-style(rgb(43, 43, 43), rgba(0, 0, 0, 0.288)); }
    }
  }

  .sheet-header-toggle {
    text-align: right;
    margin-bottom: 0.5rem;

    button {
      font-family: "DistressBlack", sans-serif;
      text-transform: uppercase;
      padding: 0.2rem 1rem;
      cursor: pointer;
      .background-image(url("@{ui-path}/scotch.webp"), no-repeat, cover, 50% 0%);
      border: none;
      box-shadow: 0px 0px 3px rgba(31, 26, 26, 0.979) inset;
      color: @theme-color-dark;

      &:hover {
        box-shadow: 0 0 10px @theme-color-highlight inset;
      }
    }
  }

  .image-wrapper {
    text-align: center;
    margin-bottom: 1rem;

    img {
      width: 80%;
      height: auto;
    }
  }

  .padding-with-frieze {
    padding: 0.25rem;

    li {
      max-width: 100%;
    }

    .resource-label {
      h4 {
        font-size: 1em;
      }
    }

    .major-totem {
      display: flex;
      justify-content: center;
      margin-bottom: 0.75rem;
      padding: 0.6rem;
      background-color: rgba(0, 0, 0, 0.12);
      border: 2px groove #eeede0;

      .flexcol {
        gap: 0.3rem;

        h4 {
          margin: 0;
          font-size: 1.1em;
        }

        .img-totem {
          width: 64px;
          height: 64px;
          filter: drop-shadow(0px 0px 10px rgb(0, 0, 0));
        }
      }
    }

    .paper {
      margin-top: 1rem;
      height: 350px;
    }

    .second-paper {
      margin-top: 4rem;
      height: 150px;
    }
  }

  .char-header {
    font-family: "DistressBlack", sans-serif;

    section {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      justify-content: flex-start;
    }

    h1.char-name,
    .char-vermine2047 {
      border-bottom: none;
      line-height: 2rem;
    }

    .char-vermine2047 {
      font-size: 1.1rem;
    }
  }

  h3 {
    font-family: "DistressBlack", sans-serif;
    text-align: center;
    text-transform: uppercase;
    color: @theme-color-light;
    font-size: 1.7rem;
    border-bottom: none;
    margin: 0;
  }

  h4 {
    font-family: "DistressBlack", sans-serif;
    font-size: 1.4em;
    text-transform: uppercase;
    margin: 0 0 0.2rem;

    &.characteristics {
      font-size: 1.25rem;
      margin-top: 0.1rem;
    }

    .tab.totem &,
    .tab.equipment &,
    .tab.stories & {
      margin-top: 0.875rem;
    }
  }

  // ── Onglet Histoire : doubler la hauteur des zones Notes et Relations ──
  .tab.stories {
    prose-mirror.editor {
      min-height: 150px;
    }
  }

  nav.tabs[data-group="sheet"] {
    display: inline-flex;
    justify-content: space-around;
    align-items: center;
    height: 54px;
    .background-image(url("@{ui-path}/barre_haut.webp"), no-repeat, auto, right top);
    background-size: 100% 100%;
    width: 100%;
    position: relative;
    padding-right: 4rem;
    font-size: 1.4rem;

    .item {
      height: 2.4rem;
      display: inline-flex;
      align-items: center;
      gap: 0.3rem;
      z-index: 1;
      transition: all 0.1s ease-out;
      color: #606060;
      box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.404);

      &:hover,
      &.active {
        color: #000;
        text-shadow: 0 5px 5px @theme-color-accent;
        cursor: pointer;
      }

      &:hover {
        text-shadow: 0 5px 5px rgba(30, 82, 37, 0.6039215686);
      }
    }
  }

  .ability {
    padding-right: 0.6rem;
    font-size: 0.8rem;
    border-bottom: 1px solid rgba(170, 170, 152, 0.664);
    box-shadow: 0px 0px 15px rgba(128, 128, 128, 0) inset;
    transition: 0.2s;
    position: relative;
    flex-wrap: nowrap;
    min-width: min-content;
    container-type: inline-size;
    container-name: ability-row;

    &:hover {
      box-shadow: 0px 0px 15px gray inset;
    }

    label {
      min-width: 40%;
      flex: 1.3;
    }

    span {
      max-width: fit-content;
      margin: 0 1rem;
      flex: 0.5;
    }

    div.specialties {
      position: absolute;
      bottom: -0.2rem;
      font-size: 0.7rem;
    }

    .skill-dots {
      height: 100%;
      align-self: center;
      flex: 1.5;
      min-width: fit-content;

      > div {
        max-width: 0.7rem;
        height: 0.7rem;
        aspect-ratio: 1/1;
        border-radius: 50%;
        font-weight: 700;
        text-align: center;
        padding-bottom: 0.2rem;
        font-style: oblique;
        align-self: flex-start;

        &.dice-pool-dot {
          .background-image(radial-gradient(circle, @dice-pool-color 25%, rgb(0, 0, 0) 100%), @dice-pool-color);
          max-width: 0.7rem;
          aspect-ratio: 1/1;
          border-radius: 50%;
        }

        &.dice-reroll-dot {
          background: radial-gradient(circle, @dice-reroll-color 25%, rgb(0, 0, 0) 100%);
        }
      }
    }
  }

  .skill-category {
    padding: 0.3rem;

    &.preferred {
      box-shadow: 0px 0px 30px rgba(0, 128, 0, 0.306) inset;

      h4, label {
        text-shadow: 0px 0px 5px rgba(0, 128, 0, 0.411);
      }
    }
  }

  #edit {
    background-color: #000;
    color: #fff;
    width: 100%;
  }

  .reserve-grid {
    line-height: 0.5rem;
    transform-origin: 0% 50%;
    max-width: fit-content;
    align-items: center;
    display: flex;
    flex-direction: column;

    div.flexrow,
    input,
    .hexa {
      margin: 0;
      padding: 0;
      min-width: 1rem;
      min-height: 1rem;
    }

    > .flexrow {
      position: relative;
      max-width: fit-content;
      justify-content: center;
    }
  }

  .fetiche-block {
    gap: 12px;
    margin: 6px 0;
    padding: 6px 8px;
    border: 1px dashed @color-hemolymph;
    background: fade(@color-hemolymph, 8%);
    border-radius: 3px;

    .fetiche-info {
      gap: 2px;
      flex: 1;

      h4 {
        margin: 0;
        font-family: "DistressBlack";
        text-transform: uppercase;
        font-size: @font-size-12;
        color: @theme-color-dark;
      }

      .fetiche-bonus {
        margin: 0;
        font-family: "Roboto", sans-serif;
        font-size: @font-size-11;
        color: @color-acid-green;
      }

      .fetiche-warning {
        margin: 0;
        font-family: "Roboto", sans-serif;
        font-size: @font-size-11;
        font-weight: 700;
        color: @color-hemolymph;
      }
    }

    button {
      flex: none;
      font-family: "DistressBlack";
      text-transform: uppercase;
      font-size: @font-size-11;
      padding: 4px 10px;
      cursor: pointer;
      color: @theme-color-dark;
      background: fade(@color-hemolymph, 20%);
      border: 1px solid @color-hemolymph;
      border-radius: 3px;
      .transition();

      &:hover {
        color: @theme-color-dark;
        background: @color-hemolymph;
      }
    }
  }

  .items-list {
    .item-name .item-image {
      flex: 0 0 30px;
      height: 30px;
      background-size: 30px;
      border: none;
      margin-right: 5px;
    }
  }

  .items-list .item.flexrow > div:not(.item-name):not(.item-controls) {
    text-align: center;
  }

  .list-item {
    list-style: none;
    margin: 0;
    padding: 0;

    .item {
      align-items: center;
      padding: 2px;
      border-bottom: 1px solid rgba(170, 170, 152, 0.664);

      &:last-child { border-bottom: none; }
    }

    .evolution-badge {
      margin-left: 6px;
      padding: 1px 6px;
      font-family: "Roboto", sans-serif;
      font-size: @font-size-11;
      text-transform: uppercase;
      border-radius: 3px;

      &.adaptation {
        color: @color-text-dark-header;
        background: fade(@color-acid-green, 25%);
        border: 1px solid @color-acid-green;
      }

      &.mutation {
        color: @color-text-dark-header;
        background: fade(@color-hemolymph, 30%);
        border: 1px solid @color-hemolymph;
      }
    }
  }

  // ── V2 tab navigation — chitin-plate style ─────────────────────────
  nav.sheet-tabs[data-application-part="tabs"] {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: 0;
    background: @color-chitin-dark;
    border-bottom: 2px solid @color-hemolymph;
    min-height: 36px;

    > a {
      font-family: "DistressBlack", sans-serif;
      text-transform: uppercase;
      font-size: @font-size-11;
      letter-spacing: 0.5px;
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 6px 16px;
      color: @color-text-light-0;
      opacity: 1;
      transition: background 0.15s;
      position: relative;
      border-right: 1px solid fade(@color-membrane, 12%);

      &:hover {
        background: fade(@color-honeycomb, 10%);
        text-shadow: none;
      }

      &.active {
        background: @color-honeycomb;
        color: @color-chitin-dark;

        &::after {
          content: '';
          position: absolute;
          bottom: -2px;
          left: 0;
          right: 0;
          height: 2px;
          background: @color-acid-green;
        }
      }

      > i {
        font-size: @font-size-14;
        width: 16px;
        text-align: center;
      }

      > span, > i {
        color: inherit;
      }
    }
  }
}

@container ability-row (max-width: 240px) {
  .skill-dots,
  span.hexa {
    display: none;
  }
}
