:root {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family:
    "Hiragino Kaku Gothic ProN",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    sans-serif;
  background:
    linear-gradient(var(--grid-line-light) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line-strong) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0 18px;
  border-bottom: 2px solid var(--ink);
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.18;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.button,
.icon-button {
  border: 1px solid var(--ink);
  border-radius: 8px;
  min-height: 42px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--ink);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background-color 120ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-weight: 800;
  text-decoration: none;
}

.button:hover,
.icon-button:hover,
.slot-button:hover,
.result-button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.button:active,
.icon-button:active,
.slot-button:active,
.result-button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.button.primary {
  color: #fff;
  background: var(--red);
}

.button.secondary {
  background: var(--surface);
}

.page-link {
  gap: 8px;
  min-height: 48px;
  padding: 6px 14px;
  text-align: left;
}

.page-link-meta {
  flex: 0 0 auto;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--paper);
  font-size: 11px;
  line-height: 1.2;
}

.page-link-title {
  min-width: 0;
  line-height: 1.25;
}

.page-link-arrow {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
  gap: 20px;
  align-items: start;
  padding-top: 22px;
}

.builder,
.preview-panel {
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--panel-translucent);
  box-shadow: var(--shadow);
}

.builder {
  padding: 18px;
}

.preview-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
}

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

.count {
  flex: 0 0 auto;
  margin: 0;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  color: #fff;
  background: var(--indigo);
  font-size: 13px;
  font-weight: 900;
}

.name-field,
.search-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.name-field {
  margin-bottom: 16px;
}

.name-field input,
.search-field input {
  width: 100%;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 12px 13px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

.name-field input:focus,
.search-field input:focus {
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.slot-grid,
.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.slot-cell {
  position: relative;
  display: flex;
  min-width: 0;
}

.slot-cell .slot-button {
  height: 100%;
}

.slot-button {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  width: 100%;
  min-height: 156px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--ink);
  text-align: left;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background-color 120ms ease;
}

.slot-button.is-empty {
  place-items: center;
  grid-template-rows: auto;
  min-height: 156px;
  border-style: dashed;
  color: var(--muted);
  text-align: center;
}

.slot-number,
.slot-english,
.result-english,
.preview-number,
.preview-empty-text,
.preview-english {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.portrait {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background:
    linear-gradient(135deg, transparent 47%, var(--portrait-cross) 48%, var(--portrait-cross) 52%, transparent 53%),
    var(--blank);
}

.portrait img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.slot-main {
  display: grid;
  gap: 5px;
  align-content: start;
  min-width: 0;
}

.slot-name {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.2;
}

.slot-remove {
  z-index: 2;
  padding: 0;
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  background: var(--surface);
  font-size: 18px;
  line-height: 1;
}

.slot-empty-text {
  display: grid;
  gap: 4px;
  place-items: center;
  font-weight: 900;
}

.slot-empty-text span:first-child {
  font-size: 28px;
  line-height: 1;
}

.share-card {
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--ink);
}

.share-card-header {
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.share-kicker,
.share-footer {
  margin: 0;
  color: var(--red-dark);
  font-size: 12px;
  font-weight: 900;
}

.share-card h3 {
  margin: 5px 0 0;
  font-size: 26px;
  line-height: 1.2;
}

.preview-grid {
  gap: 8px;
  padding: 14px 0;
}

.preview-tile {
  display: grid;
  grid-template-rows: auto auto minmax(32px, 1fr);
  gap: 6px;
  align-content: start;
  min-width: 0;
  min-height: 108px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel);
}

.preview-tile.is-empty {
  color: var(--muted);
  border-style: dashed;
  text-align: center;
}

.preview-number {
  display: block;
}

.preview-portrait-container {
  display: block;
  min-width: 0;
}

.preview-portrait {
  aspect-ratio: 1 / 1;
}

.preview-portrait-placeholder {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background:
    linear-gradient(135deg, transparent 47%, var(--placeholder-cross) 48%, var(--placeholder-cross) 52%, transparent 53%),
    var(--blank-soft);
}

.preview-body {
  display: grid;
  gap: 2px;
  align-content: start;
  min-width: 0;
}

.preview-name {
  margin: 0;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
}

.preview-empty-text {
  margin: 0;
  align-self: center;
}

.share-footer {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  text-align: right;
}

.status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.turnstile-container {
  display: flex;
  justify-content: center;
  min-height: 70px;
  margin: 16px 0 4px;
}

.picker-shell {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.picker-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
}

.picker {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  width: min(900px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  box-shadow: 8px 8px 0 var(--ink);
}

.picker-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 24px;
  font-weight: 900;
}


.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  overflow: auto;
  padding: 2px 4px 6px 2px;
}

.result-item {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.result-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-height: 112px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--ink);
  text-align: left;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease;
}

.result-item.is-picked .result-button {
  background: var(--surface-picked);
}

.result-portrait {
  width: 66px;
  height: 82px;
  aspect-ratio: auto;
  flex: 0 0 auto;
}

.result-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.result-name {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.2;
}

.wiki-link {
  width: fit-content;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--indigo);
  background: var(--surface);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.wiki-link:hover {
  background: var(--surface-picked);
}

.result-picked {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 2px 7px;
  color: #fff;
  background: var(--indigo);
  font-size: 11px;
  font-weight: 900;
}

.empty-results {
  grid-column: 1 / -1;
  border: 1px dashed var(--ink);
  border-radius: 8px;
  padding: 20px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
  font-weight: 800;
}

.search-limit-message {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: var(--line-wash);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  margin-top: 10px;
}

/* Community Section */
.community-section {
  margin-top: 32px;
  border-top: 2px solid var(--ink);
  padding-top: 24px;
}

.community-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 20px;
  align-items: start;
}

.community-card {
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--panel-translucent);
  box-shadow: var(--shadow);
  padding: 18px;
}

.community-title {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.25;
}

/* Ranking List */
.ranking-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking-item {
  display: grid;
  grid-template-columns: 28px 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface);
  box-shadow: 2px 2px 0 var(--ink);
}

.ranking-badge {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  background: var(--line-wash);
  font-size: 12px;
  font-weight: 900;
}

.ranking-item:nth-child(1) .ranking-badge {
  background: #ffd700;
}
.ranking-item:nth-child(2) .ranking-badge {
  background: #c0c0c0;
}
.ranking-item:nth-child(3) .ranking-badge {
  background: #cd7f32;
}

.ranking-portrait-container {
  display: block;
  width: 40px;
  height: 50px;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--blank-soft);
}

.ranking-portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ranking-details {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.ranking-name {
  margin: 0;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
}

.ranking-english {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.ranking-votes {
  font-size: 13px;
  font-weight: 900;
  color: var(--red);
}

/* Recent Submissions */
.recent-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.recent-item {
  display: grid;
  gap: 10px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  align-content: start;
}

.recent-item:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}

.recent-item:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.recent-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.recent-owner {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

/* Mini 3x3 grid for recent submission preview */
.recent-mini-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  aspect-ratio: 1 / 1;
  width: 96px;
  margin: 0 auto;
}

.recent-mini-cell {
  position: relative;
  border: 1px solid var(--ink);
  border-radius: 3px;
  overflow: hidden;
  background: var(--blank-soft);
}

.recent-mini-cell.is-empty {
  border-style: dashed;
}

.recent-mini-portrait {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.community-empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--ink);
  border-radius: 8px;
  padding: 24px;
  color: var(--muted);
  background: var(--surface);
  text-align: center;
  font-weight: 800;
  font-size: 13px;
}

.site-footer {
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.7;
}

.site-footer p {
  margin: 0;
}

/* Button cooldown/loading state */
.button:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: 3px 3px 0 var(--ink) !important;
}

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

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .top-actions {
    justify-content: start;
  }

  .workspace {
    display: grid;
  }

  .preview-panel {
    position: static;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  h1 {
    font-size: 24px;
  }

  .builder,
  .preview-panel,
  .picker {
    padding: 12px;
  }

  .button {
    flex: 1 1 auto;
    min-width: 96px;
    padding: 0 10px;
  }

  .slot-grid {
    gap: 7px;
  }

  .slot-button {
    min-height: 142px;
    padding: 8px;
  }

  .slot-name {
    font-size: 16px;
  }

  .slot-english {
    font-size: 11px;
  }

  .slot-remove {
    width: 24px;
    height: 24px;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .picker-shell {
    padding: 10px;
  }
}

@media (max-width: 390px) {
  .slot-grid,
  .preview-grid {
    gap: 5px;
  }

  .slot-button {
    min-height: 132px;
  }

  .slot-number,
  .slot-english,
  .preview-english {
    font-size: 10px;
  }
}
