/*
 * realm-hud-fable-pack-v2.css  (ZERO REALM, /tools/realm)
 * Replaces realm-hud-fable-pack.css. Link only one of the two.
 *
 * What it is
 *   1. A look-only storybook layer (brass and gold frames, parchment panel headers, warm dark glass) for every width.
 *      It changes colors, shadows and outlines only, so no box moves on a desktop screen. Same as v1.
 *   2. Phone touch-ups (max-width 600px) on top of the phone layout that the page itself now has
 *      (full width top panel, boss bar, zone row, chat, .hotbar-skills grid, .hotbar-menu row).
 *      The page order and structure are kept. What this adds:
 *        - the five HUD panels flow one under another by their real height (the page uses fixed top offsets,
 *          which collide as soon as a row gets taller), so nothing can cover anything in any language
 *        - every tap target is at least 40 px (language buttons, nav chips, boss and town buttons, chat, menu chips)
 *        - no label is cut: the title may use two lines, the zone label wraps instead of ending in dots
 *        - skill buttons own their size (58 px tall, label always on one line) with room for an icon medallion;
 *          it works with and without the rcr-host class and the rcr-slot child
 *
 * How to use it
 *   - Link it AFTER the inline style of the page:
 *       <link rel="stylesheet" href="/tools/realm/realm-hud-fable-pack-v2.css" />
 *   - Switch the whole pack on with ONE class on <html> or <body>:  class="rfp-on"
 *     Without that class nothing on the page changes (only the --rfp-* color variables exist on :root).
 *   - It uses the ids and classes that are already in the page. No new markup, no script.
 *
 * Shared palette (also for the icon medallions): the --rfp-* custom properties on :root below.
 */

:root {
  --rfp-brass: #b8893b;
  --rfp-gold: #f3c969;
  --rfp-ink: #1c1a2e;
  --rfp-parchment: #f4e7c8;
  --rfp-emerald: #3fae7a;
  --rfp-teal: #2f8fa6;
  --rfp-violet: #6b4fa3;
  --rfp-glass: rgba(28, 26, 46, 0.92);
  --rfp-text: #f4e7c8;
  --rfp-text-soft: #e6d9bb;
  --rfp-ink-soft: #453f5c;
  --rfp-teal-light: #8fd6e6;
  --rfp-emerald-light: #6fd0a0;
  --rfp-violet-deep: #3b2a66;
}

/* ---------- 1. Look layer, every width (colors, shadows, outlines only) ---------- */

.rfp-on {
  --panel: var(--rfp-glass);
  --border: rgba(184, 137, 59, 0.62);
  --gold: var(--rfp-gold);
  --ink: var(--rfp-text);
  --ink-soft: var(--rfp-text-soft);
  --cyan: var(--rfp-teal-light);
  --emerald: var(--rfp-emerald-light);
}

.rfp-on .panel {
  background-color: var(--rfp-glass);
  background-image: linear-gradient(180deg, rgba(58, 48, 74, 0.55), rgba(28, 26, 46, 0.2));
  border-color: var(--rfp-brass);
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(28, 26, 46, 0.95), 0 0 0 2px rgba(243, 201, 105, 0.42), inset 0 0 0 1px rgba(243, 201, 105, 0.16), 0 10px 26px rgba(0, 0, 0, 0.5);
}
.rfp-on #boss-bar-wrap {
  box-shadow: 0 0 0 1px rgba(28, 26, 46, 0.95), 0 0 0 2px rgba(107, 79, 163, 0.85), inset 0 0 0 1px rgba(243, 201, 105, 0.16), 0 10px 26px rgba(0, 0, 0, 0.5);
}

/* parchment headers: the spread shadow draws the label plate, so the row keeps its size */
.rfp-on .tl-head,
.rfp-on .boss-head,
.rfp-on #chat-box > div:first-child {
  background-color: var(--rfp-parchment);
  border-radius: 3px;
  box-shadow: 0 0 0 3px var(--rfp-parchment), 0 0 0 4px var(--rfp-brass);
  color: var(--rfp-ink) !important;
}
.rfp-on .tl-head .brand { color: var(--rfp-ink); }
.rfp-on #boss-title { color: var(--rfp-violet-deep) !important; }
.rfp-on #chat-box > div:first-child > span { color: var(--rfp-ink) !important; }
.rfp-on #chat-box > div:first-child > span + span { color: var(--rfp-ink-soft) !important; }

.rfp-on .hero-title { color: var(--rfp-text); }
.rfp-on .stat-row { color: var(--rfp-text-soft); }
.rfp-on #gold-text { color: var(--rfp-gold) !important; }
.rfp-on #fair-text { color: var(--rfp-emerald-light) !important; }
.rfp-on #boss-tip-text { color: var(--rfp-gold) !important; }
.rfp-on #zone-label { color: var(--rfp-gold); }
.rfp-on #online-label { color: var(--rfp-emerald-light); }

.rfp-on .bar {
  background-color: rgba(244, 231, 200, 0.14);
  box-shadow: inset 0 0 0 1px rgba(184, 137, 59, 0.6);
}
.rfp-on #minimap {
  border-color: var(--rfp-brass);
  background-color: #12101f;
  box-shadow: 0 0 0 1px rgba(243, 201, 105, 0.3);
}

.rfp-on .chip-btn {
  background-color: #23203a;
  border-color: var(--rfp-brass);
  color: var(--rfp-text);
  box-shadow: inset 0 1px 0 rgba(243, 201, 105, 0.18);
}
.rfp-on .chip-btn:hover { border-color: var(--rfp-gold); color: var(--rfp-gold); }
.rfp-on .chip-btn.gold { background-color: #3a2f24; border-color: var(--rfp-gold); color: var(--rfp-gold); }
.rfp-on .chip-btn.cyan { background-color: #1d2a3d; border-color: var(--rfp-teal); color: var(--rfp-teal-light); }
.rfp-on .chip-btn.active { background-color: var(--rfp-gold); border-color: #8a6420; color: var(--rfp-ink); }

.rfp-on .skill-btn {
  background-color: #23203a;
  background-image: linear-gradient(180deg, #2f2a48, #1c1a2e);
  border-color: var(--rfp-brass);
  color: var(--rfp-text);
  box-shadow: inset 0 1px 0 rgba(243, 201, 105, 0.28), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.rfp-on .skill-btn:hover { border-color: var(--rfp-gold); }
.rfp-on .skill-btn .k { color: var(--rfp-gold); }
.rfp-on .skill-btn .nm { color: var(--rfp-text-soft); }
.rfp-on .skill-btn .cd { background-color: rgba(18, 16, 31, 0.84); color: var(--rfp-gold); }

.rfp-on #chat-log { color: var(--rfp-text-soft); }
.rfp-on .chat-line strong { color: var(--rfp-gold); }
.rfp-on .chat-line.ai strong { color: var(--rfp-teal-light); }
.rfp-on .chat-line.sys { color: var(--rfp-gold); }
.rfp-on #chat-input {
  background-color: #12101f;
  border-color: var(--rfp-brass);
  color: var(--rfp-text);
  caret-color: var(--rfp-gold);
}
.rfp-on #chat-input:focus { border-color: var(--rfp-gold); }

.rfp-on .tag-name { text-shadow: 0 0 2px #1c1a2e, 0 0 4px #1c1a2e, 0 1px 3px #1c1a2e; }
.rfp-on .tag-bubble { background-color: rgba(28, 26, 46, 0.94); border-color: var(--rfp-brass); color: var(--rfp-parchment); }

.rfp-on .toast {
  background-color: rgba(28, 26, 46, 0.96);
  border-color: var(--rfp-gold);
  color: var(--rfp-parchment);
  box-shadow: 0 0 0 1px rgba(28, 26, 46, 0.95), 0 8px 20px rgba(0, 0, 0, 0.5);
}

.rfp-on #modal-card {
  background-color: rgba(28, 26, 46, 0.97);
  border-color: var(--rfp-brass);
  box-shadow: 0 0 0 1px rgba(28, 26, 46, 0.95), 0 0 0 2px rgba(243, 201, 105, 0.42), 0 24px 60px rgba(0, 0, 0, 0.6);
}
.rfp-on .card { background-color: #29253f; border-color: rgba(184, 137, 59, 0.6); }
.rfp-on .card.active { background-color: #3a2f24; border-color: var(--rfp-gold); }
.rfp-on .card-title { color: var(--rfp-text); }
.rfp-on .card-desc { color: var(--rfp-text-soft); }

.rfp-on .intro-card {
  background-color: rgba(28, 26, 46, 0.96);
  border-color: var(--rfp-brass);
  box-shadow: 0 0 0 1px rgba(28, 26, 46, 0.95), 0 0 0 2px rgba(243, 201, 105, 0.42), 0 24px 60px rgba(0, 0, 0, 0.65);
}
.rfp-on .intro-card h1 { color: var(--rfp-gold); text-shadow: 0 2px 0 #5a4116; }
.rfp-on .intro-card p { color: var(--rfp-text-soft); }
.rfp-on .start-btn {
  background-image: linear-gradient(135deg, #b8893b, #f3c969);
  border-color: var(--rfp-gold);
  color: var(--rfp-ink);
  box-shadow: 0 0 0 1px #5a4116, 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* focus rings: gold ring with a dark gap so it shows on dark glass and on parchment */
.rfp-on .chip-btn:focus-visible,
.rfp-on .skill-btn:focus-visible,
.rfp-on .start-btn:focus-visible,
.rfp-on #chat-input:focus-visible {
  outline: 2px solid var(--rfp-gold);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--rfp-ink);
}

/* ---------- 2. Phone touch-ups, portrait, up to 600 px wide (on top of the page's own phone layout) ---------- */

@media (max-width: 600px) {
  /* the panels keep the page order but stack by their real height */
  .rfp-on #hud {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "top" "boss" "zone" "free" "chat" "keys";
    gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom)) 6px;
  }
  .rfp-on #hud > .panel { position: static; transform: none; width: auto; min-width: 0; max-width: none; }
  .rfp-on #hud > #top-left { grid-area: top; }
  .rfp-on #hud > #boss-bar-wrap { grid-area: boss; }
  .rfp-on #hud > #top-right { grid-area: zone; }
  .rfp-on #hud > #chat-box { grid-area: chat; }
  .rfp-on #hud > #hotbar { grid-area: keys; }

  /* top panel */
  .rfp-on .tl-head { gap: 8px; }
  .rfp-on #top-left .brand {
    min-width: 0;
    font-size: 0.69rem;
    letter-spacing: 0.03em;
    line-height: 1.3;
    white-space: normal;
    word-break: keep-all;
    text-wrap: balance;
  }
  .rfp-on .tl-head > div { flex: 0 0 auto; }
  .rfp-on #top-left [data-lang],
  .rfp-on .intro-card [data-lang] {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    justify-content: center;
    font-size: 0.8rem;
  }
  .rfp-on #top-left .hero-title { line-height: 1.3; }
  .rfp-on #top-left > .stat-row { flex-wrap: wrap; gap: 0 10px; line-height: 1.3; }
  .rfp-on #top-left > .stat-row > span { word-break: keep-all; }
  .rfp-on #top-left .nav-strip { margin-top: 2px; padding-bottom: 0; overscroll-behavior-x: contain; touch-action: pan-x; }
  .rfp-on #top-left .nav-strip .chip-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.72rem;
    justify-content: center;
    word-break: keep-all;
  }

  /* boss bar */
  .rfp-on #boss-bar-wrap { padding: 7px 9px; gap: 5px; }
  .rfp-on .boss-head { gap: 8px; }
  .rfp-on #boss-title { min-width: 0; line-height: 1.3; word-break: keep-all; }
  .rfp-on #btn-tp-boss { flex: 0 0 auto; min-height: 40px; padding: 0 10px; word-break: keep-all; }

  /* zone row: labels on the left (two lines), town button on the right */
  .rfp-on #hud > #top-right {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    row-gap: 1px;
    padding: 6px 9px;
  }
  .rfp-on #zone-label {
    grid-column: 1;
    grid-row: 1;
    white-space: normal;
    overflow: visible;
    line-height: 1.25;
    text-align: left;
    word-break: keep-all;
  }
  .rfp-on #online-label { grid-column: 1; grid-row: 2; font-size: 0.69rem; white-space: normal; line-height: 1.25; word-break: keep-all; }
  .rfp-on #btn-tp-town {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-height: 40px;
    padding: 0 10px;
    word-break: keep-all;
  }

  /* chat */
  .rfp-on #chat-box { padding: 7px 9px; gap: 5px; }
  .rfp-on #chat-box > div:first-child { gap: 2px 8px; flex-wrap: wrap; }
  .rfp-on #chat-log { overscroll-behavior: contain; touch-action: pan-y; }
  .rfp-on #chat-box:focus-within #chat-log { height: 84px; }
  .rfp-on #chat-form { gap: 6px; }
  .rfp-on #chat-input { min-width: 0; min-height: 40px; padding: 4px 10px; font-size: 16px; }
  .rfp-on #chat-form .chip-btn {
    flex: 0 0 auto;
    min-width: 56px;
    min-height: 40px;
    padding: 0 12px;
    justify-content: center;
    white-space: nowrap;
    word-break: keep-all;
  }

  /* hotbar: the page's .hotbar-skills grid and .hotbar-menu row are kept */
  .rfp-on #hotbar { padding: 7px; gap: 6px; }
  .rfp-on .hotbar-skills { gap: 4px; align-items: stretch; }
  .rfp-on .hotbar-skills .skill-btn {
    height: auto;
    min-height: 58px;
    padding: 15px 1px 4px;
    gap: 2px;
    justify-content: flex-end;
    overflow: visible;
  }
  .rfp-on .hotbar-skills .skill-btn .k { top: 2px; left: 4px; font-size: 0.69rem; line-height: 1; }
  .rfp-on .hotbar-skills .skill-btn .ic { font-size: 1.15rem; flex: 0 0 auto; }
  .rfp-on .hotbar-skills .skill-btn.rcr-host { padding-top: 4px; }
  .rfp-on .hotbar-skills .skill-btn .rcr-slot { flex: 0 0 auto; }
  .rfp-on .hotbar-skills .skill-btn .nm {
    flex: 0 0 auto;
    max-width: none;
    overflow: visible;
    font-size: 0.69rem;
    line-height: 1.2;
    white-space: nowrap;
    word-break: keep-all;
  }
  .rfp-on .hotbar-menu { overscroll-behavior-x: contain; touch-action: pan-x; }
  .rfp-on .hotbar-menu .chip-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0 12px;
    justify-content: center;
    font-size: 0.76rem;
    word-break: keep-all;
  }

  /* toasts: in the free middle, below the zone row */
  .rfp-on #toast-area { top: 318px; max-width: calc(100vw - 16px); }
  .rfp-on .toast { word-break: keep-all; }

  /* modal: finger sized tabs and close button */
  .rfp-on #modal-backdrop { padding: 8px; }
  .rfp-on #modal-card { padding: 12px; max-height: 88vh; }
  .rfp-on .modal-head { align-items: flex-start; }
  .rfp-on .modal-tabs .chip-btn,
  .rfp-on #btn-close-modal,
  .rfp-on #modal-body .chip-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0 10px;
    word-break: keep-all;
  }
  .rfp-on #btn-close-modal { flex: 0 0 auto; white-space: nowrap; }
}

/* short phones: the chat loses its header row and shows one line */
@media (max-width: 600px) and (max-height: 700px) {
  .rfp-on #chat-box > div:first-child { display: none !important; }
  .rfp-on #chat-log { height: 18px; }
  .rfp-on #toast-area { top: 300px; }
}
