* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  touch-action: manipulation;
  overflow: hidden;
}

body {
  min-height: 100dvh;
}

button {
  font-family: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

a {
  color: inherit;
  text-decoration: none;
}

#home-view,
#tool-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#home-view[hidden],
#tool-view[hidden] {
  display: none;
}

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-height);
  margin: max(var(--space-3), var(--safe-top)) max(var(--space-3), var(--safe-right)) 0
    max(var(--space-3), var(--safe-left));
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  background: var(--color-bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  position: relative;
}

.topbar--home {
  justify-content: center;
}

.topbar--tool {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  column-gap: var(--space-2);
}

.app-title,
.topbar-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.app-title {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.app-title-logo {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.topbar-title {
  grid-column: 2;
  justify-self: center;
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-link {
  grid-column: 1;
  justify-self: start;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  z-index: 1;
}

.back-link__short {
  display: none;
}

@media (max-width: 480px) {
  .back-link__full {
    display: none;
  }
  .back-link__short {
    display: inline;
  }
}

.back-link:active {
  background: rgba(255, 255, 255, 0.1);
}

.topbar-action {
  grid-column: 3;
  justify-self: end;
  font-size: 1rem;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.12);
}

.topbar-action:active {
  background: rgba(255, 255, 255, 0.2);
}

.tool-container {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
