/* ── Reset ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Los botones no heredan font-family automáticamente en ningún navegador */
button, input, select, textarea {
  font-family: inherit;
}

/* ── Variables: modo claro ── */
:root {
  --blue:   #b5e9ec;
  --green:  #bbe9ba;
  --yellow: #f9e558;
  --pink:   #fec3dd;
  --purple: #ccaafe;

  --toolbar-bg:     rgba(255, 255, 255, 0.75);
  --toolbar-bg-solid: rgba(255, 255, 255, 0.92);
  --toolbar-border: rgba(0, 0, 0, 0.10);
  --toolbar-shadow: 0 2px 16px rgba(0,0,0,0.10);
  --toolbar-offset: 74px;
  --btn-text:       #333;
  --btn-hover:      rgba(0,0,0,0.07);
  --count-color:    #555;    /* era #666 — mejora ratio sobre toolbar semitransparente */
  --modal-bg:       #fff;
  --modal-overlay:  rgba(0,0,0,0.45);
  --note-text:      #131313;
  --char-ok:        rgba(0,0,0,0.30);
  --drag-shadow:    rgba(0,0,0,0.35);
  --help-bg:        #fff;
  --help-border:    rgba(0,0,0,0.10);
  --help-shadow:    0 8px 32px rgba(0,0,0,0.15);
  --help-text:      #333;
  --help-item-hover:rgba(0,0,0,0.04);
  --note-size:      clamp(202px, 72vw, 300px);
  --note-padding:   20px 20px 30px;
  --note-font-size: clamp(22px, 7vw, 29px);
  --thumbtack-size: 46px;
  --thumbtack-top:  -14px;
  --board-gap-row:  50px;
  --board-gap-col:  5%;
  --color-dot-size: 17px;
  --color-menu-trigger-size: 18px;
  --color-menu-dot-size: 26px;
}

/* ── Variables: modo oscuro ── */
@media (prefers-color-scheme: dark) {
  :root {
    --blue:   #6DC0C5;
    --green:  #78bb77;
    --yellow: #CDBF65;
    --pink:   #E18EA8;
    --purple: #A288D3;

    --toolbar-bg:     rgba(28, 28, 28, 0.88);
    --toolbar-bg-solid: rgba(28, 28, 28, 0.96);
    --toolbar-border: rgba(255,255,255,0.08);
    --toolbar-shadow: 0 2px 16px rgba(0,0,0,0.50);
    --btn-text:       #eee;
    --btn-hover:      rgba(255,255,255,0.10);
    --count-color:    #bbb;    /* era #999 — mejora ratio sobre toolbar oscura */
    --modal-bg:       #252525;
    --modal-overlay:  rgba(0,0,0,0.70);
    --note-text:      #111;
    --char-ok:        rgba(0,0,0,0.35);
    --drag-shadow:    rgba(0,0,0,0.60);
    --help-bg:        #252525;
    --help-border:    rgba(255,255,255,0.08);
    --help-shadow:    0 8px 32px rgba(0,0,0,0.50);
    --help-text:      #ddd;
    --help-item-hover:rgba(255,255,255,0.05);
  }
}

/* ── Base ── */
html { overflow-y: scroll; scroll-behavior: smooth; }
html, body { height: 100%; }

body {
  font-family: "Caveat", cursive; /* herencia global — evita repetir en cada regla */
  background: url("./images/cork-board.jpg") no-repeat center center fixed;
  background-image: image-set(
    url("./images/cork-board.webp") type("image/webp"),
    url("./images/cork-board.jpg") type("image/jpeg")
  );
  background-size: cover;
  min-height: 100vh;
  padding-top: var(--toolbar-offset);
}
@media (max-width: 640px) {
  body { background-attachment: scroll; } /* fix iOS Safari con fixed */
}

/* ── Overlay oscuro (solo dark mode) ── */
.dark-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
@media (prefers-color-scheme: dark) {
  .dark-overlay {
    display: block;
    background: rgba(0, 0, 0, 0.45);
  }
}

/* ── Toolbar ── */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-border);
  box-shadow: var(--toolbar-shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .toolbar {
    background: var(--toolbar-bg-solid);
  }
}

.toolbar button {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--btn-text);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.18s, transform 0.12s;
  white-space: nowrap;
}
.toolbar button:hover  { background: var(--btn-hover); }
.toolbar button:active { transform: scale(0.95); }
.toolbar button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  background: currentColor;
  -webkit-mask: var(--icon-url) center / contain no-repeat;
  mask: var(--icon-url) center / contain no-repeat;
}
.icon-plus            { --icon-url: url("./images/icons/plus-solid.svg"); }
.icon-trash           { --icon-url: url("./images/icons/trash-solid.svg"); }
.icon-circle-question { --icon-url: url("./images/icons/circle-question-solid.svg"); }
.icon-xmark           { --icon-url: url("./images/icons/xmark-solid.svg"); }
.icon-pencil          { --icon-url: url("./images/icons/pencil-solid.svg"); }
.icon-thumbtack       { --icon-url: url("./images/icons/thumbtack-solid.svg"); }
.icon-palette         { --icon-url: url("./images/icons/palette-solid.svg"); }
.icon-move            { --icon-url: url("./images/icons/move.svg"); }
.icon-floppy-disk     { --icon-url: url("./images/icons/floppy-disk-solid.svg"); }
.toolbar button .icon { font-size: 14px; }
#create    { font-weight: 600; }
#clear-all { color: #c0392b; }
#help-btn  { margin-left: 4px; font-size: 18px; }
@media (prefers-color-scheme: dark) {
  #clear-all { color: #e57373; }
  #help-btn  { color: #bbb; } /* era #aaa — mejora ratio sobre toolbar oscura */
}

.note-count {
  margin-left: auto;
  font-size: 16px;
  color: var(--count-color);
  white-space: nowrap;
  cursor: default;
}

/* ── Panel de ayuda ── */
.help-panel {
  position: fixed;
  top: 62px;
  right: 16px;
  z-index: 150;
  width: min(340px, calc(100vw - 32px));
  background: var(--help-bg);
  border: 1px solid var(--help-border);
  border-radius: 14px;
  box-shadow: var(--help-shadow);
  animation: popIn 0.22s cubic-bezier(0.34,1.56,0.64,1);
  overflow: hidden;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}
.help-panel[hidden] { display: none; }

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-size: 20px;
  font-weight: 600;
  color: var(--help-text);
  border-bottom: 1px solid var(--help-border);
  cursor: default;
}
.help-header h2 {
  font-size: inherit;
  font-weight: inherit;
  margin: 0;
}
.help-header button {
  background: none;
  border: none;
  color: var(--help-text);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.help-header button:hover        { background: var(--btn-hover); }
.help-header button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}
.help-header button:focus-visible { outline: 2px solid var(--help-text); outline-offset: 2px; }

.help-list {
  list-style: none;
  padding: 8px 0 12px;
}
.help-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 16px;
  font-size: 17px;
  color: var(--help-text);
  transition: background 0.12s;
  cursor: default;
}
.help-list li:hover { background: var(--help-item-hover); }
.help-list li .icon {
  margin-top: 2px;
  font-size: 13px;
  width: 16px;
  height: 16px;
  text-align: center;
  color: #595959; /* era #888 (ratio 3.54:1, falla AA) — #595959 da 7:1, pasa AAA */
  flex-shrink: 0;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.18s ease;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--modal-bg);
  border-radius: 14px;
  padding: 28px 32px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: popIn 0.2s cubic-bezier(0.34,1.56,0.64,1);
  max-width: calc(100vw - 40px);
}
.modal p {
  font-size: 22px;
  color: var(--btn-text);
  text-align: center;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
  margin: 0;
}
.modal-actions li { display: contents; }
.modal-actions button {
  padding: 8px 22px;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.15s;
}
.modal-actions button:active      { transform: scale(0.96); }
.modal-actions button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}
#modal-confirm { background: #e74c3c; color: #fff; }
#modal-confirm:hover { opacity: 0.88; }
#modal-confirm:focus-visible { outline: 2px solid #c0392b; outline-offset: 2px; }
#modal-cancel { background: var(--btn-hover); color: var(--btn-text); }
#modal-cancel:hover { opacity: 0.75; }
#modal-cancel:focus-visible { outline: 2px solid var(--btn-text); outline-offset: 2px; }

/* ── Board ── */
.container {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--note-size)), var(--note-size)));
  justify-content: center;
  align-content: start;
  gap: var(--board-gap-row) var(--board-gap-col);
  width: 90%;
  max-width: 1500px;
  margin: 30px auto;
  min-height: calc(100vh - var(--toolbar-offset) - 66px);
  padding-bottom: 50px;
}

/* ── Nota ── */
.note {
  position: relative;
  color: var(--note-text);
  width: min(100%, var(--note-size));
  aspect-ratio: 1;
  padding: var(--note-padding);
  border-radius: 2px;
  box-shadow: rgba(0,0,0,0.16) 0px 3px 6px, rgba(0,0,0,0.23) 0px 3px 6px;
  transition: box-shadow 0.22s, transform 0.22s;
  cursor: grab;
  user-select: none;
  animation: noteIn 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
  transform: rotate(var(--rotation, 0deg));
}
.note.appeared {
  animation: none;
}
.note:hover {
  box-shadow: rgba(0,0,0,0.22) 0px 8px 18px, rgba(0,0,0,0.18) 0px 4px 8px;
  transform: rotate(var(--rotation, 0deg)) translateY(-3px);
}
.note.dragging {
  opacity: 0.82;
  cursor: grabbing;
  transform: scale(1.04) rotate(2deg);
  box-shadow: 0 20px 50px var(--drag-shadow);
  z-index: 50;
  transition: none;
  animation: none;
}
.note.removing {
  animation: noteOut 0.25s ease forwards;
  pointer-events: none;
}

/* ── Chinche ── */
.note .thumbtack-button {
  position: absolute;
  width: var(--thumbtack-size);
  height: var(--thumbtack-size);
  top: var(--thumbtack-top);
  left: 50%;
  transform: translateX(-50%);
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 0.18s, filter 0.18s;
  z-index: 2;
}
.note .thumbtack-button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
  border-radius: 50%;
}
.note .thumbtack {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
.note .thumbtack-button:hover {
  transform: translateX(-50%) scale(1.15) rotate(-15deg);
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
}

/* ── Accesibilidad: reducir movimiento ── */
@media (prefers-reduced-motion: reduce) {
  /* Desactivar todas las animaciones y transiciones */
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* Desactivar backdrop-filter costoso */
  .toolbar {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--toolbar-bg);
  }
}

/* ── Selector de color ── */
.note .color-picker {
  position: absolute;
  bottom: 7px;
  right: 8px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}
.note:hover .color-picker,
.note:focus-within .color-picker { opacity: 1; }

.color-dot {
  width: var(--color-dot-size);
  height: var(--color-dot-size);
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.20);
  cursor: pointer;
  background-clip: padding-box;
  outline: none;
  transition: transform 0.15s, border-color 0.15s;
}
.color-dot:hover         { transform: scale(1.32); border-color: rgba(0,0,0,0.45); }
.color-dot:focus-visible { outline: 2px solid #444; outline-offset: 2px; }

/* ── Menú desplegable de color ── */
.note .color-menu       { display: none; }

@media (hover: none), (pointer: coarse), screen and (max-width: 400px) {
  :root {
    --color-menu-trigger-size: 28px;
    --color-menu-dot-size: 28px;
  }

  .note .color-picker   { display: none; }

  .note .color-menu {
    display: block;
    position: absolute;
    bottom: 4px;
    right: 4px;
    z-index: 10;
  }

  .note .color-menu-trigger {
    width: var(--color-menu-trigger-size);
    height: var(--color-menu-trigger-size);
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.25);
    cursor: pointer;
    outline: none;
    transition: transform 0.15s, border-color 0.15s;
    display: block;
  }
  .note .color-menu-trigger:hover        { transform: scale(1.2); border-color: rgba(0,0,0,0.5); }
  .note .color-menu-trigger:focus-visible { outline: 2px solid #444; outline-offset: 2px; }

  .note .input {
    padding-right: calc(var(--color-menu-trigger-size) + 6px);
    padding-bottom: calc(var(--color-menu-trigger-size) + 2px);
  }

  .note .color-menu-panel {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    display: flex;
    flex-direction: column-reverse;
    gap: 7px;
    background: rgba(255,255,255,0.92);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity 0.18s, transform 0.18s;
  }

  .note .color-menu.open .color-menu-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .note .color-menu .color-dot {
    width: var(--color-menu-dot-size);
    height: var(--color-menu-dot-size);
    display: block;
  }
}

/* ── Área de texto ── */
.note .input {
  outline: none;
  width: 100%;
  height: 100%;
  font-size: var(--note-font-size);
  overflow: hidden;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  line-height: 1.4;
  word-break: normal;
  overflow-wrap: break-word;
  hyphens: none;
  -webkit-hyphens: none;
  padding-right: 8px;
  box-sizing: border-box;
}

/* ── Contador de líneas (oculto visualmente) ── */
.note .char-count {
  display: none;
}

/* ── Animaciones ── */
@keyframes noteIn {
  from { opacity: 0; transform: scale(0.7) rotate(var(--rotation, 0deg)); }
  to   { opacity: 1; transform: scale(1)   rotate(var(--rotation, 0deg)); }
}
@keyframes noteOut {
  from { opacity: 1; transform: scale(1)   rotate(var(--rotation, 0deg)); }
  to   { opacity: 0; transform: scale(0.6) rotate(var(--rotation, 0deg)); }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes popIn {
  from { transform: scale(0.82); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ════════════════════════════
   RESPONSIVE
   ════════════════════════════ */
@media screen and (max-width: 1024px) {
  :root { --board-gap-col: 4%; }
}
@media screen and (max-width: 640px) {
  :root {
    --toolbar-offset: 66px;
    --note-padding: 16px 16px 26px;
    --thumbtack-size: 40px;
    --board-gap-row: 40px;
    --board-gap-col: 3%;
  }
  html, body { overflow-x: hidden; }
  .toolbar { padding: 6px 12px; gap: 4px; }
  .toolbar button span:not(.icon) { display: none; }
  .toolbar button { padding: 7px 10px; }
  .toolbar button .icon { font-size: 15px; }
  .container {
    justify-items: center;
    width: 95%;
  }
}

@media (prefers-color-scheme: dark) {
  .note .color-menu-panel {
    background: rgba(40,40,40,0.95);
  }
}
@media screen and (max-width: 400px) {
  :root {
    --toolbar-offset: 60px;
    --note-padding: 12px 16px 24px;
    --thumbtack-size: 36px;
    --thumbtack-top: -12px;
    --board-gap-row: 36px;
    --board-gap-col: 3%;
    --color-menu-trigger-size: 28px;
    --color-menu-dot-size: 28px;
  }
  /* altura 222px: 222 - 12 - 24 = 186px útiles → floor(186/30.8) = 6 líneas */
  .note .char-count { font-size: 11px; }
  .container {
    justify-items: center;
    width: 100%;
    margin: 20px auto;
  }
}
@media screen and (max-width: 320px) {
  :root {
    --note-padding: 8px 12px 8px;
  }
  /* altura 202px: 202 - 8 - 8 = 186px útiles → floor(186/30.8) = 6 líneas */
  .modal { padding: 20px 18px; }
  .container { justify-items: center; }
}
