/* One artwork, one page (D-031). The room viewer's design — the drawing
   framed on its room's wall, under its light — with its cartela beneath:
   title, artist, date, description and tags, a row of icons, then the
   notes, all one composition on the wall. Unlike the exhibition's viewer,
   which keeps the whole drawing on one screen, this page scrolls. The
   wall, tone and frame rules of the room viewer apply as they are (the
   page is a .room-viewer); this file lets it scroll, sets the cartela and
   tints the reactions with the room's wall. */

html:has(.obra) body {
  height: auto;
  min-height: 100vh;
  overflow: visible;
  display: block;
}
.room-viewer.obra {
  display: block;
  overflow: visible;
  max-width: none;
  padding: 0 var(--gutter) 4rem;
}
.obra > .flash { margin: 0.75rem 0 0; }

/* The drawing fits the first screen with its label under it: at most the
   height left by the header, the steps and the label. The stage is as tall
   as the drawing, so a wide drawing leaves no empty wall before its label. */
.obra .viewer-stage {
  --obra-art: clamp(15rem, calc(100svh - 18rem), 60rem);
  height: auto;
  margin-top: 0.5rem;
  padding: clamp(0.75rem, 3vw, 2.25rem) 0 clamp(1rem, 3vw, 2rem);
  background: radial-gradient(ellipse 55% 45% at 50% 0%, var(--light), transparent 75%) no-repeat;
}
/* With the script, a finger on the drawing still scrolls the page; a swipe
   sideways steps and two fingers zoom. Once zoomed, the finger pans it. */
.obra .viewer-stage img { max-height: var(--obra-art); }
html.viewer-ready .obra .viewer-stage { touch-action: pan-y; }
html.viewer-ready .obra .viewer-stage.is-zoomed { touch-action: none; }

.obra > .exhibit-label { padding-top: 0.25rem; }
.room-viewer.obra .exhibit-label h1 { font-size: clamp(1.75rem, 5.5vw, 2.6rem); }
.obra > .exhibit-label > span { font-size: 0.95rem; }
/* A hidden work says so under its title, quietly and only to its
   guardians (D-036); the switch to show it is the eye in the actions. */
.obra .exhibit-label .obra-hidden {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}
.obra-hidden .icon { flex: none; width: 1rem; height: 1rem; }

/* ---------- The cartela: what a museum hangs beside a work ----------
   Centred under the title, in the same quiet column: the date and who has
   it, the description, the tags. No field names; what is empty is not
   there. */
.obra-cartela { max-width: 34rem; margin: 0 auto; }
.obra-meta {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  text-wrap: balance;
}
.obra-meta time, .obra-meta b { white-space: nowrap; }
.obra-meta i, .obra-meta b { font-style: normal; font-weight: inherit; }
.obra-description {
  margin: 0.6rem 0 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.35;
  white-space: pre-line;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}
.obra-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 0.6rem;
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}
.obra-tags a {
  display: inline-block;
  padding: 0.3rem 0.1rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.obra-tags a:hover { color: var(--ink); }

/* ---------- The actions: icons in a quiet circle ----------
   Each icon sits in a 44 px circle of the same veil as the notes, with no
   border, so the row reads as part of the label on any wall. A toggle
   shows its state in the icon (a filled sparkle, a slashed eye) and
   aria-pressed. */
.obra-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 0.5rem;
  margin: 0.75rem auto 0;
  max-width: 34rem;
}
.obra-actions form.inline { display: contents; }
.obra-icon,
.obra-actions form.inline button.obra-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--veil);
  color: var(--muted);
  transition: color 0.18s, opacity 0.18s;
}
.obra-icon .icon { width: 1.5rem; height: 1.5rem; }
.obra-icon:hover,
.obra-actions form.inline button.obra-icon:hover { color: var(--ink); background: var(--veil); text-decoration: none; }
.obra-icon[aria-pressed="true"] { color: var(--ink); }
.obra-icon:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.obra-icon[aria-busy="true"] { opacity: 0.5; }
.obra-actions .obra-trash:hover { color: var(--danger); }

/* ---------- «Más»: the rest of the actions, behind three dots ----------
   A <details> whose summary is one more round icon. Its entries carry
   their icon and their name, 44 px tall, on the same veil; a switch shows
   its state in the icon and in a small track; the trash comes last, apart,
   in the danger colour. On a wide screen it drops under the dots (or rises
   over them, obra-mas.js, when there is no room below); on a phone it is a
   small sheet that stands on the tab bar, never under it. */
.obra-mas { position: relative; display: inline-flex; }
.obra-mas > summary { list-style: none; cursor: pointer; }
.obra-mas > summary::-webkit-details-marker { display: none; }
.obra-mas[open] > summary { color: var(--ink); }
.obra-mas-panel {
  position: absolute;
  z-index: 15;
  top: calc(100% + 0.45rem);
  right: 0;
  width: max-content;
  min-width: 15rem;
  max-width: min(20rem, calc(100vw - 2rem));
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  border-radius: 16px;
  background: var(--veil);
  box-shadow: 0 0 0 1px var(--veil-line), 0 18px 40px -18px #00000073, 0 4px 10px -6px #00000033;
  text-align: left;
}
.obra-mas.is-up .obra-mas-panel { top: auto; bottom: calc(100% + 0.45rem); }
@starting-style {
  .obra-mas[open] .obra-mas-panel { opacity: 0; transform: translateY(-4px); }
}
.obra-mas-panel { transition: opacity 0.16s var(--ease), transform 0.16s var(--ease); }
.obra-mas-entry { margin: 0; padding: 0; }
.obra-mas-entry.is-apart {
  margin-top: 0.3rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--veil-line);
}
.obra-mas-panel form.inline { display: block; }
.obra-mas-item,
.obra-mas-panel form.inline button.obra-mas-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.8rem;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}
.obra-mas-item .icon { flex: none; width: 1.35rem; height: 1.35rem; color: var(--muted); }
.obra-mas-label { flex: 1; }
.obra-mas-item:hover { text-decoration: none; }
/* Only a pointer that hovers lights an entry: on a phone the tap that
   opened the sheet would leave the entry under it lit. */
@media (hover: hover) {
  .obra-mas-item:hover,
  .obra-mas-panel form.inline button.obra-mas-item:hover {
    background: color-mix(in srgb, var(--ink) 7%, transparent);
    color: var(--ink);
  }
}
.obra-mas-item:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.obra-mas-item[aria-busy="true"] { opacity: 0.5; }
.obra-mas-item[aria-pressed="true"] .icon { color: var(--ink); }
/* A switch's state: a small track, filled while it is on. */
.obra-mas-switch {
  position: relative;
  flex: none;
  width: 1.9rem;
  height: 1.1rem;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1.5px var(--muted);
}
.obra-mas-switch::after {
  content: "";
  position: absolute;
  top: 0.25rem;
  left: 0.25rem;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 999px;
  background: var(--muted);
  transition: transform 0.16s var(--ease);
}
[aria-pressed="true"] > .obra-mas-switch { background: var(--ink); box-shadow: none; }
[aria-pressed="true"] > .obra-mas-switch::after { background: var(--veil); transform: translateX(0.8rem); }
.obra-mas-panel .obra-trash,
.obra-mas-panel .obra-trash .icon,
.obra-mas-panel .obra-trash:hover { color: var(--danger); }
/* On a dark wall by day the danger colour sits just under 4.5:1 on the
   terracotta veil; the trash's words take a lighter step of it. */
@media (prefers-color-scheme: light) {
  .obra[data-tone="dark"] .obra-mas-panel :is(.obra-trash, .obra-trash .icon, .obra-trash:hover) { color: #f3aea6; }
}
@media (prefers-reduced-motion: reduce) {
  .obra-mas-panel, .obra-mas-switch::after { transition: none; }
}
@media (max-width: 40rem) {
  .obra-mas-panel {
    position: fixed;
    z-index: 25;
    top: auto;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(5.75rem + env(safe-area-inset-bottom));
    width: auto;
    min-width: 0;
    max-width: 26rem;
    margin: 0 auto;
    max-height: calc(100svh - 7.5rem - env(safe-area-inset-bottom) - env(safe-area-inset-top));
    overflow-y: auto;
    border-radius: 18px;
  }
  .obra-mas.is-up .obra-mas-panel { bottom: calc(5.75rem + env(safe-area-inset-bottom)); }
  @starting-style {
    .obra-mas[open] .obra-mas-panel { opacity: 0; transform: translateY(10px); }
  }
  .obra-mas-item, .obra-mas-panel form.inline button.obra-mas-item { min-height: 3rem; font-size: 1rem; }
}

/* ---------- Reactions in the room's colours ----------
   The notes, the heart and the note field are a veil of the wall, not
   white paper: lighter than a light wall, a shade deeper on a dark wall
   (whose text is light) and a touch lighter on a night wall. Text keeps
   the tone's ink, so it reads as it does on the wall itself. */
.obra {
  --veil: color-mix(in srgb, var(--wall) 45%, #fff);
  --veil-line: color-mix(in srgb, var(--ink) 11%, transparent);
  --paper: var(--veil);
  --field: var(--veil);
}
@media (prefers-color-scheme: light) {
  .obra[data-tone="dark"] { --veil: color-mix(in srgb, var(--wall) 78%, #000); }
}
@media (prefers-color-scheme: dark) {
  .obra { --veil: color-mix(in srgb, var(--wall) 90%, #fff); }
}
/* The cartela's secondary grey on warm-stone and ochre by day is the
   walls' own rule in tanda-d.css, shared with the room. */
.obra .reactions {
  max-width: 34rem;
  margin: 1.25rem auto 0;
  padding-top: 0;
  border-top: 0;
}
.obra .reactions-bar { justify-content: center; text-align: center; }
.obra button.heart { background: var(--veil); border-color: var(--veil-line); }
.obra button.heart:hover { background: var(--veil); border-color: var(--faint); }
.obra .note { border-color: var(--veil-line); }
.obra .note-form textarea { border-color: var(--veil-line); }
.obra .note-form textarea:focus { border-color: var(--ink); }
.obra .note-form textarea::placeholder { color: var(--muted); opacity: 0.85; }
.obra .notes-head h2 { font-size: 1.35rem; }

/* A phone: the tab bar sits over the bottom of the page, so the page ends
   above it. */
@media (max-width: 40rem) {
  .room-viewer.obra { padding-bottom: calc(6rem + env(safe-area-inset-bottom)); }
  .obra .viewer-stage { --obra-art: clamp(13rem, calc(100svh - 20.5rem), 40rem); }
}

/* A phone on its side: the drawing keeps most of the height. */
@media (orientation: landscape) and (max-height: 32rem) {
  .obra .viewer-stage { --obra-art: max(12rem, calc(100svh - 9rem)); }
}
