@import url("https://fonts.googleapis.com/css2?family=Libre+Caslon+Text:ital,wght@0,400;0,700;1,400&display=swap");

:root {
  --font-family: sans-serif;
  --font-size: 1rem;
  --spacing: 1.5rem;
  --padding: 1.75rem;
  --gap: var(--spacing);
  --input-padding: 0.5rem;
  --input-height: 2.375rem;
  --max-width: 65rem;
  --logo-width: 150px;
  --logo-height: 100px;

  --hue: 120deg;
  --saturation: 0%;
  --lightness: 95%;

  --color-primary: hsl(var(--hue), var(--saturation), var(--lightness));
  --color-secondary: hsl(
    var(--hue),
    var(--saturation),
    calc(var(--lightness) + 5%)
  );
  --color-border: hsl(var(--hue), var(--saturation), 50%);
  --color-text: hsl(var(--hue), var(--saturation), 10%);
  --color-shadow: rgba(0, 0, 0, 0.05);

  --color-bg: white;
  --color-surface: var(--color-secondary);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-family);
  font-size: var(--font-size);
  color: var(--color-text);
}

body {
  padding: var(--padding);
  padding-top: 0;
  background: var(--color-bg);
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
}

header {
  margin-bottom: var(--gap);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  text-align: center;
  width: 100%;
}

.logo,
.logo-filler {
  width: var(--logo-width);
  height: var(--logo-height);
  display: flex;
  align-items: center;
}

.logo img {
  width: var(--logo-width);
  height: var(--logo-height);
  display: block;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 400;
  font-family: "Libre Caslon Text", serif;
  margin: 0;
  flex: 1;
}

section {
  background: var(--color-surface);
  padding: var(--padding);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  box-shadow: 0 4px 8px var(--color-shadow);
  margin-bottom: var(--padding);
}

fieldset {
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

legend {
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.regexp-group {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  position: relative;
}

.regexp-group .slash.left {
  position: absolute;
  left: -1rem;
  top: 0;
  font-weight: bold;
  font-size: 1.25rem;
  line-height: var(--input-height);
}

.regexp-group .slash.right {
  font-weight: bold;
  font-size: 1.25rem;
  line-height: var(--input-height);
  align-self: flex-start;
}

.regexp-group textarea,
.regexp-group input {
  padding: var(--input-padding);
  border: 1px solid var(--color-border);
  background: var(--color-secondary);
  height: var(--input-height);
  font-family: monospace;
}

.regexp-group textarea {
  resize: vertical;
  line-height: 1.4;
  flex: 1;
  min-height: 2.4rem;
}

.regexp-group input {
  width: 4rem;
  text-align: center;
  height: 2.4rem;
}

.two-column-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

button {
  padding: var(--input-padding);
  background: var(--color-secondary);
  border: 1px solid var(--color-border);
}

button:hover {
  cursor: pointer;
}

.permalink-url {
  padding-top: var(--input-padding);
  text-overflow: ellipsis;
  overflow: clip;
}

textarea {
  width: 100%;
  padding: var(--input-padding);
  border: 1px solid var(--color-border);
  background: var(--color-secondary);
  resize: vertical;
  min-height: calc(var(--spacing) * 5);
  font-family: monospace;
}

.styled-box {
  padding: var(--input-padding);
  border: 1px solid var(--color-border);
  background: var(--color-primary);
  min-height: calc(var(--spacing) * 5);
  overflow: auto;
  font-family: monospace;
}

.styled-box a {
  font-family: monospace;
}

.match {
  background: var(--color-text);
  color: var(--color-bg);
  font-family: monospace;
}

@media (max-width: 600px) {
  :root {
    --padding: 1rem;
    --spacing: 1rem;
    --logo-width: 75px;
    --logo-height: 50px;
  }

  .regexp-group {
    flex-direction: column;
    align-items: stretch;
  }

  .regexp-group .slash.left,
  .regexp-group .slash.right {
    display: none;
  }

  .regexp-group textarea,
  .regexp-group input {
    width: 100%;
  }

  .two-column-section {
    grid-template-columns: 1fr;
  }
}

section.loading {
  position: relative;
}
section.loading > * {
  filter: blur(3px);
  transition: filter 0.2s ease;
}
section.loading::after {
  content: "loading...";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

.reference h2 {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.reference h2 small {
  font-size: 0.9rem;
  opacity: 0.75;
}

/* grid layout stays the same */
.reference-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
}

/* center code + text */
.ref-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  background: var(--color-primary);
  border-radius: 4px;
  outline: none;
}

/* fixed-distance tooltip above */
.ref-item .hint {
  --hint-gap: 1rem;
  position: absolute;
  left: 50%;
  bottom: calc(100% + var(--hint-gap));
  transform: translateX(-50%);
  display: none;
  padding: 0.65rem 0.8rem;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  box-shadow: 0 6px 16px var(--color-shadow);
  border-radius: 8px;
  width: 100%;
  max-width: 100%;
  z-index: 20;
  pointer-events: none;
}
.ref-item .hint::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--color-bg);
  filter: drop-shadow(0 1px 0 var(--color-border));
}

/* show on hover/focus (mobile-friendly) */
.ref-item:hover .hint,
.ref-item:focus .hint,
.ref-item:focus-within .hint {
  display: block;
}

/* code styling */
.ref-item code,
.hint code {
  font-family: monospace;
  background: white;
  padding: 0 0.25rem;
  border-radius: 3px;
  border: 1px solid var(--color-border);
}
