:root {
  color-scheme: dark;
  --ink: #f7f4ee;
  --muted: #c9c1b6;
  --panel: rgba(16, 17, 19, 0.72);
  --panel-strong: rgba(16, 17, 19, 0.9);
  --line: rgba(255, 255, 255, 0.18);
  --accent: #4fd1b4;
  --accent-ink: #071411;
  --warn: #ffb85c;
  --danger: #ff6b6b;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: #101113;
  color: var(--ink);
}

body {
  overflow: hidden;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: fixed;
  inset: 0;
  min-width: 320px;
  background: #101113;
  overflow: hidden;
}

.camera-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(16, 17, 19, 0.2), rgba(16, 17, 19, 0.36)),
    #101113;
}

.camera-feed,
.frame-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translateZ(0);
}

.camera-feed.is-dimmed,
.frame-canvas.is-dimmed {
  filter: brightness(0.64) saturate(0.9);
}

.frame-canvas[hidden],
.processing-layer[hidden],
.control-button[hidden],
.message-panel[hidden],
.support-link[hidden] {
  display: none;
}

.ruby-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.ruby-block {
  position: absolute;
  max-width: min(86vw, 34rem);
  padding: 0.3rem 0.45rem 0.36rem;
  border: 1px solid rgba(247, 244, 238, 0.22);
  border-radius: 8px;
  background: rgba(10, 11, 12, 0.74);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
  color: #fffaf2;
  font-size: clamp(1.05rem, 2.2vh, 1.55rem);
  line-height: 1.45;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
  overflow-wrap: anywhere;
}

.ruby-block ruby {
  ruby-position: over;
}

.ruby-block rt {
  color: #b8fff0;
  font-size: 0.62em;
  line-height: 1.15;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.transcript {
  left: max(1rem, env(safe-area-inset-left));
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(6.7rem + env(safe-area-inset-bottom));
  width: auto;
}

.furigana-chip {
  position: absolute;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 4.5rem;
  padding: 0.08rem 0.18rem 0.1rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  font-size: clamp(0.68rem, 1.7vh, 0.96rem);
  font-weight: 850;
  line-height: 1.05;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  transform: translate(-50%, -100%);
  overflow-wrap: anywhere;
  pointer-events: none;
}

.furigana-chip.is-below {
  transform: translate(-50%, 0);
}

.furigana-chip.is-vertical {
  max-width: none;
  max-height: 5.2rem;
  padding: 0.16rem 0.08rem;
  writing-mode: vertical-rl;
  text-orientation: upright;
  transform: translate(0, -50%);
}

.furigana-chip.is-vertical.is-left {
  transform: translate(-100%, -50%);
}

.processing-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  gap: 0.7rem;
  background: rgba(0, 0, 0, 0.22);
  text-align: center;
}

.processing-layer p {
  margin: 4.7rem 0 0;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.spinner {
  position: absolute;
  width: 4.2rem;
  height: 4.2rem;
  border: 4px solid rgba(247, 244, 238, 0.24);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.top-bar,
.bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
}

.top-bar {
  top: 0;
  justify-content: space-between;
  min-height: 5rem;
  padding-top: max(0.85rem, env(safe-area-inset-top));
  padding-bottom: 0.75rem;
  background: linear-gradient(rgba(0, 0, 0, 0.68), rgba(0, 0, 0, 0));
}

.app-name,
.status-text {
  margin: 0;
}

.app-name {
  font-size: 1rem;
  font-weight: 780;
  line-height: 1.1;
}

.status-text {
  margin-top: 0.18rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.support-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 5.6rem;
  min-height: 2.15rem;
  padding: 0.38rem 0.52rem;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 184, 92, 0.9);
  color: #17100a;
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.bottom-bar {
  bottom: 0;
  justify-content: center;
  gap: 0.75rem;
  min-height: 6.4rem;
  padding-top: 0.8rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.78));
}

.control-button {
  min-width: 7.25rem;
  height: 3.35rem;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  font-weight: 850;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.34);
}

.control-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.control-button.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.control-button.secondary {
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
}

.message-panel {
  position: absolute;
  left: max(1rem, env(safe-area-inset-left));
  right: max(1rem, env(safe-area-inset-right));
  bottom: calc(6.5rem + env(safe-area-inset-bottom));
  z-index: 12;
  max-height: 38vh;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.45;
  overflow: auto;
}

.message-panel strong {
  color: var(--warn);
}

.noscript {
  position: fixed;
  inset: auto 1rem 1rem;
  z-index: 20;
  margin: 0;
  padding: 0.8rem;
  border-radius: 8px;
  background: #101113;
  color: #fff;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100vw, 28rem);
    height: min(100vh, 58rem);
    max-height: 100vh;
    margin-inline: auto;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1.8s;
  }
}
