:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 62.5%;
  --bg: #121212;
  --panel: rgba(255, 255, 255, 0.13);
  --panel-strong: rgba(255, 255, 255, 0.2);
  --line: rgba(255, 255, 255, 0.42);
  --text: #f7f7fb;
  --muted: rgba(247, 247, 251, 0.72);
  --accent: #7e74c9;
  --accent-strong: #9d92df;
  --surface: #ffffff;
  --surface-text: #282833;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1.5;
}

button,
input {
  border: 0;
  border-radius: 4px;
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

code {
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.08);
  padding: 0.08em 0.28em;
}

#app {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  scrollbar-width: none;
  background: linear-gradient(135deg, #111 0%, #181820 48%, #101012 100%);
}

#app::-webkit-scrollbar {
  display: none;
}

#app.cursor-hidden,
#app.cursor-hidden * {
  cursor: none !important;
}

.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.welcome {
  width: min(640px, calc(100vw - 40px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
  animation: fade-in 0.28s ease-out both, slide-up 0.28s ease-out both;
}

.welcome h1 {
  margin: 0 0 12px;
  font-size: clamp(2.4rem, 3vw, 3.8rem);
  line-height: 1.15;
}

.welcome p {
  margin: 12px 0;
  color: var(--muted);
}

.welcome-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.primary-button,
.toolbar button,
.dialog-actions button,
.move-banner button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.primary-button:hover,
.toolbar button:hover,
.dialog-actions button:hover,
.move-banner button:hover {
  background: var(--accent-strong);
}

.primary-button:active,
.toolbar button:active,
.dialog-actions button:active,
.move-banner button:active {
  transform: translateY(1px);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 800;
}

.video-grid {
  display: grid;
  grid-gap: 0;
  counter-reset: tile;
}

.clock-overlay {
  position: absolute;
  z-index: 18;
  min-width: 170px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.46);
  color: rgba(255, 255, 255, 0.86);
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
  pointer-events: none;
  transition: top 0.8s ease, right 0.8s ease, bottom 0.8s ease, left 0.8s ease, transform 0.8s ease, opacity 0.2s ease;
}

.clock-date {
  font-size: 1.3rem;
  line-height: 1.2;
}

.clock-time {
  margin-top: 2px;
  font-family: "Segoe UI", Consolas, monospace;
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
}

.clock-pos-0 {
  top: 16px;
  right: 18px;
  transform: translate(0, 0);
}

.clock-pos-1 {
  top: 28px;
  left: 24px;
  transform: translate(6px, 4px);
}

.clock-pos-2 {
  right: 28px;
  bottom: 24px;
  transform: translate(-5px, -4px);
}

.clock-pos-3 {
  left: 18px;
  bottom: 32px;
  transform: translate(4px, -6px);
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.82);
  animation: scale-in 0.18s ease-out both;
}

.tile.empty::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.06) 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
}

.player-host,
.player-host iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.player-host iframe {
  border: 0;
}

.url-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  position: absolute;
  inset: 0;
  z-index: 10;
  padding: 18px;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  background: rgba(0, 0, 0, 0.74);
  color: var(--text);
}

.url-panel.hidden {
  display: none;
}

.url-panel label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 1.3rem;
}

.url-panel input {
  width: min(440px, 100%);
  height: 34px;
  padding: 0 10px;
  border: 2px solid rgba(255, 255, 255, 0.66);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
}

.url-panel input:focus {
  outline: 0;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(157, 146, 223, 0.28);
}

.url-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.url-actions button {
  width: 100px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.86);
  color: #262632;
  font-weight: 700;
}

.url-actions .set-video {
  background: var(--accent);
  color: #fff;
}

.move-layer {
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
  z-index: 20;
  border: 2px dashed rgba(255, 255, 255, 0.74);
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
  cursor: move;
  user-select: none;
}

.move-layer::before {
  counter-increment: tile;
  content: counter(tile);
  font-size: clamp(3.2rem, 5vw, 7rem);
  font-weight: 800;
}

.move-mode .move-layer {
  display: flex;
}

.tile.drag-over .move-layer {
  background: rgba(126, 116, 201, 0.78);
}

.tile.dragging {
  opacity: 0.42;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 64px;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.16);
}

.toolbar button {
  min-width: 78px;
  background: #303038;
  font-size: 1.4rem;
}

.toolbar button:hover {
  background: #474752;
}

.toolbar button[aria-pressed="true"] {
  border-color: rgba(157, 146, 223, 0.7);
  background: #655c98;
}

.move-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  z-index: 40;
  transform: translateX(-50%);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(10px);
}

.first-hint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 25;
  width: min(360px, calc(100vw - 40px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(126, 116, 201, 0.8);
  border-radius: 8px;
  background: #f1efff;
  color: #2d2949;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  animation: fade-away 5s 2s both;
}

.first-hint p {
  margin: 0 0 4px;
  font-size: 1.3rem;
  font-weight: 700;
}

.first-hint span {
  display: inline-block;
  font-size: 2.4rem;
  line-height: 1;
  animation: bounce 1.3s infinite;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--surface-text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.layout-dialog {
  width: min(940px, calc(100vw - 32px));
}

.layout-dialog form,
.help-dialog form,
.share-dialog form {
  margin: 0;
  padding: 22px;
  background: var(--surface);
}

.layout-dialog h2,
.help-dialog h2,
.share-dialog h2 {
  margin: 0 0 16px;
  font-size: 2.2rem;
  line-height: 1.25;
}

.layout-choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.layout-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 92px;
  padding: 7px;
  border: 2px solid #b6b6c0;
  border-radius: 6px;
  background: #fff;
}

.layout-choice[aria-pressed="true"] {
  border-color: var(--accent);
  background: #efedff;
  box-shadow: 0 0 0 3px rgba(126, 116, 201, 0.16);
}

.layout-preview {
  display: grid;
  width: 100%;
  height: 100%;
  counter-reset: preview;
  pointer-events: none;
}

.layout-preview span {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #b9b9c5;
  background: #f2f2f5;
  color: #585866;
  font-size: 1.1rem;
  font-weight: 800;
  counter-increment: preview;
}

.layout-preview span::before {
  content: counter(preview);
}

.dialog-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.dialog-actions button {
  min-width: 120px;
}

#closeLayout {
  background: #ececf1;
  color: #282833;
}

.help-dialog,
.share-dialog {
  width: min(760px, calc(100vw - 32px));
}

.help-dialog form,
.share-dialog form {
  position: relative;
  max-height: min(720px, calc(100vh - 50px));
}

.close-button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 34px;
  height: 34px;
  background: #eeeeef;
  color: #282833;
  font-size: 2rem;
  line-height: 1;
}

.help-content {
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding-right: 8px;
}

.help-content h2 {
  margin-top: 22px;
  padding-left: 10px;
  border-left: 6px solid var(--accent);
}

.help-content h2:first-child {
  margin-top: 0;
}

.help-content p {
  margin: 10px 0;
}

.share-dialog p {
  margin: 0 42px 12px 0;
}

.share-dialog input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 2px solid #c9c9d2;
  background: #fff;
  color: #20202a;
}

.share-dialog input:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(126, 116, 201, 0.16);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 6px;
  background: #ffffff;
  color: #282833;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.3);
}

.grid-layout-1x1 {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.grid-layout-1x2 {
  grid-template-columns: 1fr;
  grid-template-rows: repeat(2, 1fr);
}

.grid-layout-2x1 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: 1fr;
}

.grid-layout-2x3 {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.grid-layout-3x2 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.grid-layout-4x4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.grid-layout-6x6 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
}

.grid-column-2-t .tile:nth-child(1) { grid-area: 1 / 2 / 3 / 4; }
.grid-column-2-t .tile:nth-child(2) { grid-area: 3 / 1 / 5 / 3; }
.grid-column-2-t .tile:nth-child(3) { grid-area: 3 / 3 / 5 / 5; }

.grid-column-2-b .tile:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.grid-column-2-b .tile:nth-child(2) { grid-area: 1 / 3 / 3 / 5; }
.grid-column-2-b .tile:nth-child(3) { grid-area: 3 / 2 / 5 / 4; }

.grid-column-2x2 .tile:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.grid-column-2x2 .tile:nth-child(2) { grid-area: 1 / 3 / 3 / 5; }
.grid-column-2x2 .tile:nth-child(3) { grid-area: 3 / 1 / 5 / 3; }
.grid-column-2x2 .tile:nth-child(4) { grid-area: 3 / 3 / 5 / 5; }

.grid-column-3x3 .tile:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.grid-column-3x3 .tile:nth-child(2) { grid-area: 1 / 3 / 3 / 5; }
.grid-column-3x3 .tile:nth-child(3) { grid-area: 1 / 5 / 3 / 7; }
.grid-column-3x3 .tile:nth-child(4) { grid-area: 3 / 1 / 5 / 3; }
.grid-column-3x3 .tile:nth-child(5) { grid-area: 3 / 3 / 5 / 5; }
.grid-column-3x3 .tile:nth-child(6) { grid-area: 3 / 5 / 5 / 7; }
.grid-column-3x3 .tile:nth-child(7) { grid-area: 5 / 1 / 7 / 3; }
.grid-column-3x3 .tile:nth-child(8) { grid-area: 5 / 3 / 7 / 5; }
.grid-column-3x3 .tile:nth-child(9) { grid-area: 5 / 5 / 7 / 7; }

.grid-column-large.grid-layout-2x3 .tile:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.grid-column-large.grid-layout-3x2 .tile:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.grid-column-large.grid-layout-6x6 .tile:nth-child(1) { grid-area: 1 / 1 / 5 / 5; }
.grid-column-large.grid-layout-6x6 .tile:nth-child(2) { grid-area: 1 / 5 / 3 / 7; }
.grid-column-large.grid-layout-6x6 .tile:nth-child(3) { grid-area: 3 / 5 / 5 / 7; }
.grid-column-large.grid-layout-6x6 .tile:nth-child(4) { grid-area: 5 / 1 / 7 / 3; }
.grid-column-large.grid-layout-6x6 .tile:nth-child(5) { grid-area: 5 / 3 / 7 / 5; }
.grid-column-large.grid-layout-6x6 .tile:nth-child(6) { grid-area: 5 / 5 / 7 / 7; }

.l-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.l-2 { width: 50%; grid-template-columns: 1fr; grid-template-rows: repeat(2, 1fr); }
.l-3 { height: 50%; grid-template-columns: repeat(2, 1fr); grid-template-rows: 1fr; }
.l-4 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.l-4 span:nth-child(1) { grid-area: 1 / 2 / 3 / 4; }
.l-4 span:nth-child(2) { grid-area: 3 / 1 / 5 / 3; }
.l-4 span:nth-child(3) { grid-area: 3 / 3 / 5 / 5; }
.l-5 { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.l-5 span:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.l-5 span:nth-child(2) { grid-area: 1 / 3 / 3 / 5; }
.l-5 span:nth-child(3) { grid-area: 3 / 2 / 5 / 4; }
.l-6 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.l-7 { width: 66.66%; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); }
.l-8 { height: 66.66%; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
.l-9 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.l-10 { width: 66.66%; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(3, 1fr); }
.l-10 span:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.l-11 { height: 66.66%; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); }
.l-11 span:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }
.l-12 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.l-12 span:nth-child(1) { grid-area: 1 / 1 / 3 / 3; }

@media (max-width: 480px), (min-aspect-ratio: 9 / 16) {
  .grid-layout-1x1,
  .grid-layout-4x4,
  .grid-layout-6x6 {
    width: 100%;
    height: 56.25vw;
  }

  .grid-layout-1x2 {
    width: 88.8889vh;
    height: 100%;
  }

  .grid-layout-2x1 {
    width: 100%;
    height: 28.125vw;
  }

  .grid-layout-2x3 {
    width: 118.5185vh;
    height: 100%;
  }

  .grid-layout-3x2 {
    width: 100%;
    height: 37.5vw;
  }
}

@media (aspect-ratio: 16 / 9), (min-aspect-ratio: 16 / 9) {
  .grid-layout-1x1,
  .grid-layout-4x4,
  .grid-layout-6x6 {
    width: 177.7778vh;
    height: 100%;
  }
}

@media (max-aspect-ratio: 8 / 9) {
  .grid-layout-1x2 {
    width: 100%;
    height: 112.5vw;
  }
}

@media (min-aspect-ratio: 32 / 9) {
  .grid-layout-2x1 {
    width: 355.5556vh;
    height: 100%;
  }
}

@media (max-aspect-ratio: 32 / 27) {
  .grid-layout-2x3 {
    width: 100%;
    height: 84.375vw;
  }
}

@media (min-aspect-ratio: 8 / 3) {
  .grid-layout-3x2 {
    width: 266.6667vh;
    height: 100%;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 1.4rem;
  }

  .welcome {
    text-align: left;
  }

  .welcome-actions {
    justify-content: flex-start;
  }

  .url-panel {
    padding: 10px;
  }

  .url-panel label {
    display: none;
  }

  .url-panel input {
    height: 30px;
    font-size: 1.4rem;
  }

  .url-actions {
    width: 100%;
  }

  .url-actions button {
    flex: 1;
    width: auto;
    height: 28px;
    font-size: 1.2rem;
  }

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

  .layout-choice {
    height: auto;
    aspect-ratio: 142 / 86;
  }

  .toolbar {
    justify-content: flex-start;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .toolbar button {
    min-width: 72px;
  }

  .clock-overlay {
    min-width: 136px;
    padding: 6px 8px;
  }

  .clock-date {
    font-size: 1.1rem;
  }

  .clock-time {
    font-size: 1.9rem;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { transform: translateY(12px); }
  to { transform: translateY(0); }
}

@keyframes scale-in {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
  0%, 40%, 80%, 100% { transform: translateY(0); }
  20%, 60% { transform: translateY(5px); }
}

@keyframes fade-away {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}
