:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-strong: #eef5f2;
  --text: #1f2a2a;
  --muted: #61706f;
  --border: #d8e1de;
  --accent: #147d64;
  --accent-strong: #0c5f4a;
  --danger: #b84444;
  --shadow: 0 14px 40px rgba(25, 50, 48, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(11, 102, 178, 0.14), transparent 34%),
    linear-gradient(180deg, #f7fbff 0%, var(--bg) 42%, #edf4f2 100%);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hero {
  min-height: 22vh;
  display: flex;
  align-items: center;
  padding: 28px clamp(18px, 4vw, 48px);
  background: linear-gradient(120deg, #064f8f 0%, #0b66b2 52%, #073763 100%);
  color: #fff6df;
  overflow: hidden;
  position: relative;
}

.hero__inner {
  position: relative;
  z-index: 2;
  width: min(1120px, 100%);
  margin-left: 0;
  margin-right: auto;
  pointer-events: none;
}

.hero h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(1.2rem, 2.5vw, 2.15rem);
  line-height: 1.15;
  letter-spacing: 0;
}

.space-game {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  pointer-events: auto;
}

.space-game::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background:
    radial-gradient(circle at 78% 22%, rgba(255, 246, 223, 0.18), transparent 16%),
    radial-gradient(circle at 42% 76%, rgba(255, 255, 255, 0.12), transparent 18%);
  pointer-events: none;
}

.space-game canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

.app {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px clamp(12px, 2.8vw, 34px) 48px;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 10px;
}

.search {
  flex: 1;
  min-width: 0;
}

.search label,
.field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.search input,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.search input {
  height: 46px;
  padding: 0 14px;
}

.field input {
  height: 42px;
  padding: 0 12px;
}

.field textarea {
  min-height: 280px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

.search input:focus,
.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 125, 100, 0.12);
}

.primary-button,
.secondary-button,
.text-button,
.mini-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  white-space: nowrap;
}

.primary-button {
  min-height: 46px;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 700;
}

.text-button {
  padding: 6px 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  text-decoration: underline;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.status-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
}

.template-card {
  min-height: 104px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
  box-shadow: 0 10px 28px rgba(31, 66, 92, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.template-card:hover,
.template-card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  outline: none;
  transform: translateY(-1px);
}

.template-card--copied {
  border-color: var(--accent);
  background: #edf8f4;
}

.template-card h2 {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.template-card p {
  flex: 1;
  margin: 0;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.card-actions {
  display: flex;
  gap: 6px;
}

.mini-button {
  flex: 1;
  min-width: 0;
  min-height: 28px;
  padding: 0 8px;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 700;
}

.mini-button--danger {
  color: var(--danger);
}

.empty-state {
  margin: 48px 0;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #1f2a2a;
  color: #ffffff;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.roaming-cat-layer {
  position: fixed;
  inset: 0;
  z-index: 12;
  overflow: hidden;
  pointer-events: none;
}

.roaming-cat {
  position: absolute;
  left: 0;
  top: 0;
  width: 74px;
  height: 74px;
  pointer-events: none;
  user-select: none;
  transform-origin: center bottom;
  will-change: transform;
}

.roaming-cat img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.template-dialog {
  width: min(680px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.template-dialog::backdrop {
  background: rgba(31, 42, 42, 0.42);
}

.template-dialog form {
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.icon-button {
  width: 34px;
  height: 34px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 700;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
}

@media (min-width: 1200px) {
  .template-grid {
    grid-template-columns: repeat(9, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .hero {
    min-height: 24vh;
    padding: 24px 16px;
  }

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

  .primary-button {
    width: 100%;
  }

  .status-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

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

  .template-card {
    min-height: 100px;
    padding: 10px;
  }

  .template-card h2 {
    font-size: 0.88rem;
  }

  .roaming-cat {
    width: 58px;
    height: 58px;
  }
}

@media (max-width: 360px) {
  .template-grid {
    grid-template-columns: 1fr;
  }
}
