:root {
  color-scheme: light;
  --ink: #000;
  --paper: #fff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

#app * {
  touch-action: manipulation;
}

button {
  color: var(--ink);
}

#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  background: var(--paper);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Keep editing menus available in fields, while suppressing iOS long-press UI elsewhere. */
#app input,
#app textarea,
#app [contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: var(--paper);
  touch-action: none;
}

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(84vw, 380px);
  transform: translate(-50%, -50%);
  z-index: 5;
  text-align: center;
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid var(--ink);
  padding: 28px 22px 24px;
  box-shadow: 7px 7px 0 var(--ink);
}

.hidden {
  display: none !important;
}

.title-wrap {
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.22em;
  font-weight: 700;
}

h1,
h2,
p {
  color: var(--ink);
}

h1,
h2 {
  margin: 0;
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.05em;
}

h1 {
  font-size: clamp(40px, 11vw, 62px);
}

h2 {
  font-size: clamp(42px, 12vw, 64px);
}

.subtitle {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.5;
}

.name-row {
  margin: 0 0 14px;
  text-align: left;
}

.name-row label {
  display: block;
  margin: 0 0 6px;
  font-size: 10px;
  letter-spacing: 0.18em;
  font-weight: 700;
}

.name-row input {
  width: 100%;
  height: 48px;
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 0 12px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  font-weight: 800;
  text-transform: uppercase;
}

.name-row input:focus {
  box-shadow: inset 0 0 0 2px var(--ink);
}

.primary,
.ghost {
  width: 100%;
  min-height: 50px;
  border: 2px solid var(--ink);
  border-radius: 0;
  font-weight: 900;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.primary {
  background: var(--ink);
  color: var(--paper);
}

.ghost {
  margin-top: 10px;
  background: var(--paper);
  color: var(--ink);
}

.rank-result {
  min-height: 22px;
  margin: 12px 0 2px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.hud {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 18px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  text-align: center;
  pointer-events: none;
}

.hud span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.22em;
  font-weight: 700;
}

.hud strong {
  display: block;
  margin-top: 2px;
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
}

.in-game-title {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 18px);
  left: calc(env(safe-area-inset-left) + 14px);
  z-index: 6;
  min-width: 64px;
  height: 40px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.ranking-panel {
  width: min(88vw, 420px);
  max-height: 72dvh;
  overflow: hidden;
  text-align: left;
}

.ranking-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.close {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
}

.ranking-list {
  max-height: 44dvh;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style-position: inside;
  border-top: 2px solid var(--ink);
}

.ranking-list li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  border-bottom: 1px solid var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.ranking-list .rank {
  font-size: 11px;
}

.ranking-list .distance {
  font-variant-numeric: tabular-nums;
}

@media (max-height: 680px) {
  .panel {
    padding-top: 20px;
    padding-bottom: 18px;
  }

  .title-wrap {
    margin-bottom: 18px;
  }

  h1 {
    font-size: 42px;
  }
}


.utility-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}

.utility-button {
  min-height: 42px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.07em;
}

.new-best {
  margin: 10px 0 -2px;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.12em;
  transform: rotate(-2deg);
}

.bird-panel {
  max-height: 90dvh;
  overflow-y: auto;
  width: min(88vw, 420px);
}

.my-birds-heading { font-size: 12px; letter-spacing: 0.12em; margin: 10px 0 7px; }
.my-bird-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; max-height: 180px; overflow-y: auto; }
.my-bird-card { min-width: 0; border: 2px solid var(--ink); padding: 4px; }
.my-bird-card.selected { box-shadow: inset 0 0 0 2px var(--ink); }
.my-bird-pick { display: grid; width: 100%; padding: 3px; background: var(--paper); border: 0; font-size: 9px; font-weight: 800; gap: 3px; }
.my-bird-pick canvas { width: 100%; height: 55px; object-fit: contain; }
.my-bird-remove { border: 0; background: none; font-size: 9px; padding: 6px 2px; text-decoration: underline; }

.bird-panel h2 {
  font-size: clamp(34px, 9vw, 50px);
}

.bird-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 22px 0 4px;
}

.bird-choice {
  min-height: 112px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 6px 10px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.bird-choice.selected {
  background: var(--ink);
  color: var(--paper);
}

.bird-preview {
  display: block;
  width: 100%;
  height: 72px;
  margin: 0 auto 4px;
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}


.bird-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bird-preview-canvas {
  display: block;
  width: 100%;
  height: 72px;
  margin: 0 auto 4px;
  background: var(--paper);
}

.bird-choice.selected .bird-preview-canvas {
  background: var(--ink);
}

.draw-bird-button {
  margin-top: 10px;
}

.draw-bird-panel {
  width: min(92vw, 430px);
}

.draw-bird-panel h2 {
  font-size: clamp(34px, 9vw, 50px);
}

.draw-help {
  margin: 10px 0 12px;
  font-size: 12px;
  font-weight: 700;
}

#drawBirdCanvas {
  display: block;
  width: min(100%, 320px);
  aspect-ratio: 15 / 11;
  margin: 0 auto;
  border: 3px solid var(--ink);
  background: var(--paper);
  touch-action: none;
}

.draw-actions {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 8px;
  margin-top: 10px;
}

.draw-actions .ghost,
.draw-actions .primary {
  margin-top: 0;
}


.bird-alias {
  margin: 12px 0 8px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  word-break: break-word;
}

.bird-tools {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.bird-tools .utility-button {
  min-width: 0;
  padding: 0 5px;
}

.mini-status {
  min-height: 16px;
  margin: 7px 0 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.gallery-panel {
  width: min(92vw, 460px);
  max-height: 82dvh;
  overflow: hidden;
  text-align: left;
}

.gallery-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.gallery-panel h2,
.share-panel h2 {
  font-size: clamp(34px, 9vw, 50px);
}

.gallery-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 7px;
  margin-top: 16px;
}

.bird-code-search {
  display: flex;
  align-items: center;
  min-width: 0;
  border: 2px solid var(--ink);
  padding-left: 9px;
  font-size: 14px;
  font-weight: 800;
}

.bird-code-search:focus-within {
  box-shadow: inset 0 0 0 1px var(--ink);
}

.bird-code-search span {
  flex-shrink: 0;
}

.gallery-search input {
  min-width: 0;
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 0;
  padding: 0 6px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
}

.bird-gallery-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 48dvh;
  margin-top: 8px;
  overflow-y: auto;
  padding-right: 2px;
}

.gallery-card {
  border: 2px solid var(--ink);
  padding: 7px;
  text-align: center;
  background: var(--paper);
}

.gallery-card canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--paper);
  border-bottom: 1px solid var(--ink);
}

.gallery-card strong {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  line-height: 1.2;
  word-break: break-word;
}

.gallery-card small {
  display: block;
  margin: 3px 0 6px;
  font-size: 9px;
}

.gallery-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.gallery-card-actions button {
  min-height: 32px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 9px;
  font-weight: 900;
}

.share-panel {
  width: min(88vw, 420px);
}

#sharePreviewCanvas {
  display: block;
  width: min(100%, 300px);
  aspect-ratio: 1 / 1;
  margin: 14px auto;
  border: 2px solid var(--ink);
  background: var(--paper);
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 8px;
}

.share-grid .ghost {
  margin-top: 0;
  padding: 0 6px;
  font-size: 10px;
}


.confirm-panel {
  width: min(88vw, 410px);
}

.confirm-panel h2 {
  font-size: clamp(38px, 10vw, 54px);
}

.confirm-copy {
  margin: 14px 0;
  font-size: 12px;
  line-height: 1.55;
}

.password-field {
  display: block;
  text-align: left;
}

.password-field span {
  display: block;
  margin-bottom: 6px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.password-field input {
  width: 100%;
  height: 48px;
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 0 11px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  font-size: 16px;
  font-weight: 800;
}

.password-note {
  margin: 7px 0 12px;
  text-align: left;
  font-size: 10px;
  line-height: 1.45;
}

.danger-button {
  width: 100%;
  min-height: 50px;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-weight: 900;
  letter-spacing: 0.07em;
  box-shadow: inset 0 0 0 2px var(--paper);
}


.text-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 8px 4px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-decoration: underline;
}


.legal-links {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 8px;
}

.legal-links .text-button,
.legal-links .text-link {
  padding: 8px 4px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1.25;
}

.terms-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 2px;
  text-align: left;
  font-size: 11px;
  font-weight: 800;
}

.terms-check input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: #000;
}

.terms-panel,
.report-panel {
  width: min(90vw, 430px);
}

.terms-panel h2,
.report-panel h2 {
  font-size: clamp(36px, 9vw, 52px);
}

.terms-scroll {
  max-height: 46dvh;
  margin: 16px 0;
  overflow-y: auto;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  padding: 10px 2px;
  text-align: left;
  font-size: 11px;
  line-height: 1.55;
}

.terms-scroll p {
  margin: 7px 0;
}

.password-field select,
.password-field textarea {
  width: 100%;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  font: inherit;
  font-weight: 800;
}

.password-field select {
  height: 46px;
  padding: 0 10px;
}

.password-field textarea {
  min-height: 90px;
  padding: 10px;
  resize: vertical;
}

.report-panel .password-field + .password-field {
  margin-top: 10px;
}

.gallery-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gallery-subrow .mini-status {
  margin-right: auto;
}

.gallery-card-actions {
  grid-template-columns: 1fr 1fr;
}

.gallery-card-actions .danger-mini {
  border-style: dashed;
}

.language-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  font-size: 10px;
  font-weight: 800;
}

.language-row select {
  max-width: 65%;
  min-height: 36px;
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: 4px 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}

.panel {
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 36px);
  overflow-y: auto;
}

html:not([lang="en"]) .primary,
html:not([lang="en"]) .ghost,
html:not([lang="en"]) .utility-button,
html:not([lang="en"]) .danger-button {
  letter-spacing: 0;
  line-height: 1.3;
  padding: 8px 6px;
  overflow-wrap: anywhere;
}

html:not([lang="en"]) .panel h2 {
  line-height: 1.12;
  font-size: clamp(28px, 8vw, 44px);
  overflow-wrap: anywhere;
}

.mini-status, .rank-result, #bestDistance {
  overflow-wrap: anywhere;
}

.text-link {
  color: var(--ink);
}

#startPanel h1 {
  font-size: clamp(30px, 10vw, 46px);
}

#originalBirdPreview {
  width: min(100%, 103px);
  height: auto;
  aspect-ratio: 10 / 7;
  max-height: 72px;
}

.bird-select-main {
  width: 100%;
  margin-bottom: 8px;
}

