/*
 * Tipo Lab · the shared top bar and language switch, and the rule that shows one language.
 * Static pages link this file next to /tipo/lang.js; the Next pages import it from app/layout.tsx.
 * Colours follow the page: set --tipo-fg, --tipo-muted, --tipo-line, --tipo-accent on tipo-bar or :root,
 * or put theme="light" on <tipo-bar> (data-theme="light" on .tipo-bar).
 */

/* <html data-lang> is "zh", "en" or "both": a .zh / .en pair shows the page's language, or both. */
html[data-lang='en'] .zh,
html[data-lang='zh'] .en {
  display: none;
}

tipo-bar,
.tipo-bar {
  --tipo-fg: #eef1ea;
  --tipo-muted: #8d998f;
  --tipo-line: rgb(222 238 214 / 15%);
  --tipo-hover: rgb(255 255 255 / 6%);
  --tipo-accent: #d7ebbd;
  --tipo-accent-bg: rgb(207 227 180 / 14%);
  --tipo-lab: linear-gradient(100deg, #e1f0cb 10%, #a9cc8f 60%, #e3d4aa);
  box-sizing: border-box;
  display: flex;
  flex: none;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 12px 24px;
  color: var(--tipo-fg);
  font: 400 14px/1.2 var(--font-body, 'DM Sans'), -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei UI', sans-serif;
}

tipo-bar[theme='light'],
.tipo-bar[data-theme='light'] {
  --tipo-fg: #1f2620;
  --tipo-muted: #67706a;
  --tipo-line: rgb(31 38 32 / 16%);
  --tipo-hover: rgb(31 38 32 / 6%);
  --tipo-accent: #34502b;
  --tipo-accent-bg: rgb(52 80 43 / 11%);
  --tipo-lab: linear-gradient(100deg, #3f6a33 10%, #5d8a45 60%, #8c6a2e);
}

tipo-bar *,
.tipo-bar * {
  box-sizing: border-box;
}

.tipo-home {
  order: -3;
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  color: inherit;
  font: 600 19px/1 var(--font-heading, 'Space Grotesk'), 'DM Sans', sans-serif;
  letter-spacing: -0.04em;
  text-decoration: none;
  white-space: nowrap;
}

.tipo-mark {
  display: block;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  filter: drop-shadow(0 0 12px rgb(176 210 146 / 16%));
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.tipo-home:hover .tipo-mark {
  transform: rotate(-8deg);
}

/* Whatever comes last of the brand and the app's name pushes the buttons to the right. */
.tipo-home:not(:has(+ .tipo-crumb)) {
  margin-right: auto;
}

/* "Tipo Lab": grotesk, then a serif italic in the accent gradient, as on the homepage. */
.tipo-word i {
  padding: 0 0.08em 0.1em 0.02em;
  background: var(--tipo-lab);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font: italic 400 1.2em/1 var(--font-serif, 'Instrument Serif'), Georgia, serif;
  letter-spacing: -0.01em;
}

.tipo-crumb {
  order: -2;
  margin-right: auto;
  overflow: hidden;
  color: var(--tipo-muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tipo-slash {
  margin-right: 0.55em;
  opacity: 0.7;
}

html[data-lang='both'] .tipo-crumb .en {
  margin-left: 0.5em;
  opacity: 0.75;
}

/* 留言 / Feedback: from any app to the message board (/messages), just before 中 | EN. On a phone, the icon alone. */
.tipo-feedback {
  order: 98;
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 13px 0 11px;
  border: 1px solid var(--tipo-line);
  border-radius: 12px;
  color: var(--tipo-muted);
  font: 600 12.5px/1 var(--font-heading, 'Space Grotesk'), 'DM Sans', 'PingFang SC', 'Microsoft YaHei UI', sans-serif;
  letter-spacing: 0.03em;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tipo-feedback svg {
  flex: none;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tipo-feedback:hover {
  background: var(--tipo-hover);
  color: var(--tipo-fg);
}

.tipo-feedback:focus-visible {
  outline: 2px solid var(--tipo-accent);
  outline-offset: 2px;
}

/* In 中EN the bar is busy enough: 留言 alone. */
html[data-lang='both'] .tipo-feedback .en {
  display: none;
}

/* Words for screen readers only. */
.tipo-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 中 | EN, last on the bar. The pressed look follows <html data-lang>, so it is right before any script runs. */
.tipo-lang {
  order: 99;
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--tipo-line);
  border-radius: 12px;
}

.tipo-lang button,
.tipo-lang a {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 32px;
  margin: 0;
  padding: 0 9px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--tipo-muted);
  font: 600 12.5px/1 var(--font-heading, 'Space Grotesk'), 'DM Sans', 'PingFang SC', 'Microsoft YaHei UI', sans-serif;
  letter-spacing: 0.03em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tipo-lang button:hover,
.tipo-lang a:hover {
  background: var(--tipo-hover);
  color: var(--tipo-fg);
}

.tipo-lang button:focus-visible,
.tipo-lang a:focus-visible {
  outline: 2px solid var(--tipo-accent);
  outline-offset: 2px;
}

html[data-lang='zh'] .tipo-lang [data-tipo-lang='zh'],
html[data-lang='en'] .tipo-lang [data-tipo-lang='en'],
html[data-lang='both'] .tipo-lang [data-tipo-lang='both'] {
  background: var(--tipo-accent-bg);
  color: var(--tipo-accent);
}

@media (max-width: 640px) {
  tipo-bar,
  .tipo-bar {
    gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  }
  .tipo-home {
    gap: 9px;
    margin-right: auto;
    font-size: 17px;
  }
  .tipo-mark {
    width: 30px;
    height: 30px;
  }
  .tipo-crumb {
    display: none;
  }
  .tipo-lang button,
  .tipo-lang a {
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
  }
  .tipo-feedback {
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
  }
  .tipo-feedback-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* A phone keeps the mark, the app's buttons, 留言 and the switch; the wordmark makes room. */
@media (max-width: 420px) {
  .tipo-word {
    display: none;
  }
}

/* The narrowest phones: tighter, so a bar with three buttons, 留言 and 中 | EN | 中EN still fits in 360px. */
@media (max-width: 400px) {
  tipo-bar,
  .tipo-bar {
    gap: 6px;
  }
  .tipo-lang button,
  .tipo-lang a {
    min-width: 28px;
    padding: 0 5px;
  }
}

/* 320px (a first iPhone SE, small Androids): tighter still, the app's own buttons (.top-actions) a little closer
   together too, so a game's four or five buttons, 留言 and the switch all fit and 中 | EN can always be tapped. */
@media (max-width: 340px) {
  tipo-bar,
  .tipo-bar {
    gap: 4px;
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }
  tipo-bar .top-actions,
  .tipo-bar .top-actions {
    gap: 3px;
  }
  .tipo-mark {
    width: 28px;
    height: 28px;
  }
  .tipo-feedback {
    width: 32px;
    height: 32px;
  }
  .tipo-lang {
    padding: 2px;
  }
  .tipo-lang button,
  .tipo-lang a {
    min-width: 26px;
    padding: 0 4px;
  }
}

@media (max-height: 520px) {
  tipo-bar,
  .tipo-bar {
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .tipo-mark {
    width: 28px;
    height: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tipo-mark,
  .tipo-feedback,
  .tipo-lang button,
  .tipo-lang a {
    transition: none;
  }
}
